Saya ingin mengeluarkan mesej apabila tiada item dalam pangkalan data. ini Kod tidak mencetak penyata apabila pangkalan data tidak mempunyai data.
This is my code, <?php foreach($latest_tenders as $tenders): if(!empty($tenders)){ $time = strtotime($tenders['post_date']); $month=date('m', $time); switch($month){ case 1: echo "January "; break; . . . case 12: echo "December "; break; default: echo "January "; } echo date('d', $time).', '; echo date('Y', $time).' '; echo date('h', $time).':'; echo date('i', $time).' | ';?> <i class="fas fa-user"></i> <?php echo $tenders['author'];?></p> </div><br/> <?php } else{?> <p style=" font-size:13px; word-spacing: 5px;color:tomato;"> Tender Name: No advertised Tenders, Check again later. </p> <?php } endforeach; ?>
Bagaimana jika
$latest_tenders
是您的数据库结果,首先检查$latest_tenders
数组是否不为空。如果不为空:循环遍历$latest_tenders
并打印其$tenders
. Jika tidak (kosong): cetak mesej ralat anda.