• 20-12-2022, 15:35:50
    #1
    Selamlar,
    PHP dilinde yapmış olduğumuz küçük bir yazılım var.
    Bu yazılım ayın yemek menüsünü listeliyor ve yemekhanede tablet üzerinde yaptığımız değerlendirmeleri gün gün beğeni yüzdelerini listeliyor.
    Uygulamadan küçük bir ekran görüntüsü;

    Burada sadece bulunduğumuz ayı listelen bir sistem var.
    Bir DatePicker eklemek istiyorum ve belirtmiş olduğum tarih aralığında ki menüleri listelesin ve karşılığında o tarihlere ait beğeni oranlarını versin.
    Kaynak kodum şu şekilde;

                        <?php
                                 $Sor = $conn->query("SELECT * FROM yemeklistesi");
                                $rows = $Sor->fetchAll(PDO::FETCH_ASSOC); 
                                foreach ($rows as $row) {
                                $id = $row['id'];
                                $kullaniciadi = $row['yemek'];
                                $sifre = $row['tarih'];
                         ?>
                            <tr>
                                <td><?php echo $row['id']; ?></td>
                                <td><?php echo $row['yemek']; ?></td>
                                <td><?php echo $row['tarih']; ?></td>
                                <td style="background-color: green; color:#fff; font-size:20px;">
                                    <?php
    
                                        $bilgiler = $conn->query("SELECT * FROM yemekhane_anket");
                                        $bilgilercek=$bilgiler->fetchAll(PDO::FETCH_ASSOC);
                                            $say = 0;
                                            $mem = 0;
                                         foreach ($bilgilercek as $row2) {
                                            $a = strtotime($row2['tarih']);
                                            if(strval($row['tarih']) == strval(date('Y-m-d',$a))){
                                                $say = $say + 1;
                                            }
                                            if(strval($row['tarih']) == strval(date('Y-m-d',$a)) && strval($row2['memnuniyet_durumu']) == '1'){
                                                $mem = $mem + 1;
                                            }
                                         }
                                         if (strval($say) == '0') {
                                             echo 'Değerlendirme Yapılmamış';
                                         }else{
                                                echo round(intval($mem) * 100/intval($say));
                                                echo "%";
                                         }
                                        
                                     ?>
                                </td>
    
                            </tr>
                       <?php }
    
                        ?>
                    </tbody>
                </table>
    PHP konusunda acemiyim, bu benim yapabileceğim bir işlem midir?
  • 20-12-2022, 18:51:32
    #2
    İki adet tarih seçebilmek için html tablonun dışında bir yere aşağıdaki html kodunu ekleyin.

    <form method="GET">
        <input type="date" name="start_date" value="<?php echo empty($_GET["start_date"]) ? date("Y-m-01") : date("Y-m-d", strtotime($_GET["start_date"])); ?>">
        <input type="date" name="end_date" value="<?php echo empty($_GET["end_date"]) ? date("Y-m-t") : date("Y-m-d", strtotime($_GET["end_date"])); ?>">
        <button>Getir</button>
    </form>
    HTML inputlardan gelen tarihe göre de php sorgularınızı güncellemeniz gerekiyor,

                <?php
                    $start_date = empty($_GET["start_date"]) ? date("Y-m-01") : date("Y-m-d", strtotime($_GET["start_date"]));
                    $end_date = empty($_GET["end_date"]) ? date("Y-m-t") : date("Y-m-d", strtotime($_GET["end_date"]));
    
                    $Sor = $conn->prepare("SELECT * FROM yemeklistesi WHERE tarih >= :start_date AND tarih <= :end_date");
                    $Sor->execute([
                        "start_date" => $start_date,
                        "end_date" => $end_date
                    ]);
                    $rows = $Sor->fetchAll(PDO::FETCH_ASSOC); 
                    foreach ($rows as $row) {
                    $id = $row['id'];
                    $kullaniciadi = $row['yemek'];
                    $sifre = $row['tarih'];
             ?>
            <tr>
                <td><?php echo $row['id']; ?></td>
                <td><?php echo $row['yemek']; ?></td>
                <td><?php echo $row['tarih']; ?></td>
                <td style="background-color: green; color:#fff; font-size:20px;">
                    <?php
                        $bilgiler = $conn->prepare("SELECT * FROM yemekhane_anket WHERE tarih >= :start_date AND tarih <= :end_date");
                        $bilgiler->execute([
                            "start_date" => $start_date,
                            "end_date" => $end_date
                        ]);
                        $bilgilercek=$bilgiler->fetchAll(PDO::FETCH_ASSOC);
                            $say = 0;
                            $mem = 0;
                            foreach ($bilgilercek as $row2) {
                            $a = strtotime($row2['tarih']);
                            if(strval($row['tarih']) == strval(date('Y-m-d',$a))){
                                $say = $say + 1;
                            }
                            if(strval($row['tarih']) == strval(date('Y-m-d',$a)) && strval($row2['memnuniyet_durumu']) == '1'){
                                $mem = $mem + 1;
                            }
                            }
                            if (strval($say) == '0') {
                                echo 'Değerlendirme Yapılmamış';
                            } else{
                                echo round(intval($mem) * 100/intval($say));
                                echo "%";
                            }
                        ?>
                </td>
            </tr>
           <?php }
            ?>
        </tbody>
    </table>
  • 20-12-2022, 21:38:41
    #3
    sahinbey adlı üyeden alıntı: mesajı görüntüle
    İki adet tarih seçebilmek için html tablonun dışında bir yere aşağıdaki html kodunu ekleyin.

    <form method="GET">
        <input type="date" name="start_date" value="<?php echo empty($_GET["start_date"]) ? date("Y-m-01") : date("Y-m-d", strtotime($_GET["start_date"])); ?>">
        <input type="date" name="end_date" value="<?php echo empty($_GET["end_date"]) ? date("Y-m-t") : date("Y-m-d", strtotime($_GET["end_date"])); ?>">
        <button>Getir</button>
    </form>
    HTML inputlardan gelen tarihe göre de php sorgularınızı güncellemeniz gerekiyor,

                <?php
                    $start_date = empty($_GET["start_date"]) ? date("Y-m-01") : date("Y-m-d", strtotime($_GET["start_date"]));
                    $end_date = empty($_GET["end_date"]) ? date("Y-m-t") : date("Y-m-d", strtotime($_GET["end_date"]));
    
                    $Sor = $conn->prepare("SELECT * FROM yemeklistesi WHERE tarih >= :start_date AND tarih <= :end_date");
                    $Sor->execute([
                        "start_date" => $start_date,
                        "end_date" => $end_date
                    ]);
                    $rows = $Sor->fetchAll(PDO::FETCH_ASSOC);
                    foreach ($rows as $row) {
                    $id = $row['id'];
                    $kullaniciadi = $row['yemek'];
                    $sifre = $row['tarih'];
             ?>
            <tr>
                <td><?php echo $row['id']; ?></td>
                <td><?php echo $row['yemek']; ?></td>
                <td><?php echo $row['tarih']; ?></td>
                <td style="background-color: green; color:#fff; font-size:20px;">
                    <?php
                        $bilgiler = $conn->prepare("SELECT * FROM yemekhane_anket WHERE tarih >= :start_date AND tarih <= :end_date");
                        $bilgiler->execute([
                            "start_date" => $start_date,
                            "end_date" => $end_date
                        ]);
                        $bilgilercek=$bilgiler->fetchAll(PDO::FETCH_ASSOC);
                            $say = 0;
                            $mem = 0;
                            foreach ($bilgilercek as $row2) {
                            $a = strtotime($row2['tarih']);
                            if(strval($row['tarih']) == strval(date('Y-m-d',$a))){
                                $say = $say + 1;
                            }
                            if(strval($row['tarih']) == strval(date('Y-m-d',$a)) && strval($row2['memnuniyet_durumu']) == '1'){
                                $mem = $mem + 1;
                            }
                            }
                            if (strval($say) == '0') {
                                echo 'Değerlendirme Yapılmamış';
                            } else{
                                echo round(intval($mem) * 100/intval($say));
                                echo "%";
                            }
                        ?>
                </td>
            </tr>
           <?php }
            ?>
        </tbody>
    </table>
    Müthiş
    İlginiz için teşekkür ederim.
  • 20-12-2022, 21:44:48
    #4
    turansonkaya adlı üyeden alıntı: mesajı görüntüle
    Müthiş
    İlginiz için teşekkür ederim.
    rica ederim.