Я новичок в mysqli, я использовал этот код моего друга, но я не понимаю, как проверить, возвращает ли запрос строку zeo. Вот мой код. Заранее спасибо.
$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>'; } }
Вы можете использовать num_rows
в наборе данных, чтобы проверить количество возвращенных строк. Пример:
$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) { if($results->num_rows === 0) { echo 'No results'; } else { //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>'; } } }