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

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -