Friday, January 27, 2012

How do I echo an error message when there are no hits in a search result in PHP?

Hi, I am a PHP newbie, and I've tried this, but it doesn't work:








$result = mysql_query("SELECT * FROM book


WHERE BookID = '$bookid' AND Author = '$author' AND Title = '$title' AND Qualification = '$qual' OR (Qualification = '$qual' AND Subject = '$subject' OR Subject = '$other') OR Publisher = '$publisher' AND ISBN = '$isbn'");


echo $result;


if (empty($result)) {


echo 'Error, no such book found! Please check all the details and try again.';


}





Thanks|||Try this :


if(mysql_num_rows($result) %26lt; 1){


echo 'Sorry, no results found to match your search.';


exit;}


If you do not exit it will not display or will go on to show the page possibly over your message. Better is to create a string and include it in the page.

No comments:

Post a Comment