php - If search returns nothing give error -


i have search form on website, , want return error if user searches not exist in database

<?php  $search = $_post['search' ];  $numrows = mysql_num_rows ($result );  if($numrows != 0) echo "no results"; ?> 

this code search form using, echo"no results" shows on homepage above of results, not display when there no results search.

i'm beginner php, unsure why happening.

if need full code, below:

http://pastebin.com/xjxwhfdt

wouldn't

if($numrows == 0) echo "no results"; 

if nothing found ?

  • your $numrows = mysql_num_rows ($result ); shouldn't @ place is.

you should :

$count = count($result); if($count > 0) {     while ($row =mysql_fetch_object ($result)) {         // stuff     } } else {     echo 'no results'; } 

also, point of $search = $_post['search' ]; in while loop? don't seem use @ all.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -