I cannot operate two databases. If there is data equal to date, I print the average in one column. If there is no data equal to the date, I get the following error. I need to type an "else" but I can't get it to run when I type it. My code is as follows;
<?php
$Sor = $conn->query("SELECT * FROM yemeklistesi");
//burada satırları dizi olarak çektik
$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
// echo strtotime($row['tarih']);
$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;
}
}
echo round(intval($mem) * 100/intval($say));
?>
%</td>
</tr>
<?php }
?>
I suggest you check that the value before or inside the condition is not empty and be able to create dateTime object in a specific format
If the datetime string can create a datetime object, the above will return the datetime object, otherwise it will return a FALSE Boolean value. This way you can execute your else part.