php - Why does my echo not work given no results found? -
i performing routine check if books exist in database given range. want echo if no books found. have following:
$search = mysqli_query($con,$query); while(list($book_id, $title, $authors, $description, $price) = mysqli_fetch_row($search)){ if(!empty($book_id)) { echo "book id: " . $book_id . "<br/>"; echo "book title: " . $title . "<br/>"; echo "authors: " . $authors . "<br/>"; echo "description: " . $description . "<br/>"; echo "price: " . $price . "<br/>"; echo "<br/>"; } if(empty($book_id)){ echo "fail"; } }
if no books found nothing printed. echo not work? how come?
thanks
because if no records returned, won't enter in while @ all, $book_is contain value false , while(false)... know
in situation may use mysqli_num_rows check if there rows found
Comments
Post a Comment