10
我是mysqli的新手,我使用了我朋友的這段代碼,但我不明白如何檢查查詢是否返回zeo行。這是我的代碼。提前致謝。檢查查詢結果是否爲空行mysqli
$results = $mysqli->query("SELECT ANNOUNCE_NUMBER,ANNOUNCEMENTS,ANNOUNCE_TYPE,POST_DATE FROM home WHERE ANNOUNCE_NUMBER NOT LIKE $excludewelcome AND ANNOUNCE_NUMBER NOT LIKE $excludenews ORDER BY ANNOUNCE_NUMBER DESC LIMIT $position, $items_per_group");
if ($results) {
//output results from database
while($obj = $results->fetch_object())
{
if($obj->ANNOUNCE_TYPE=='NEWSEVENTS')
{
$realstring='News and Events';
}
else
{
$realstring='Welcome Note';
}
echo '<li id="item_'.$obj->ANNOUNCE_NUMBER.'"><strong>'.$realstring.'</strong></span>';
echo '<br \>';
echo '('.$obj->POST_DATE.') <span class="page_message">'.$obj->ANNOUNCEMENTS.'</span></li>';
}
}
謝謝!那工作! – user3196424
但我認爲最好使用一個如果: if(($ results)&&($ results-> num_rows!== 0)){ –