php - Mysql_fetch_object() SQL Query (HOW TO: If no results found, display "message" )? -


i've spent hours trying make work. no solutions search have helped me, i'm asking.

what i'm trying is: display message if no results found.

this have, , not working dismay.

    $sql = mysql_query("select * cover match(keyword,description,categories) against('$search_key' in boolean mode) order id desc limit $from , $perpage");      $i=1;     while($result = mysql_fetch_object($sql)) {      $keyword = $result->keyword;     $img = $result->img;     $description = $result->description;      if($img != null) { this;     if($i==2) { require_once(dirname(__file__).'/page.php'); }     $i++; }     }     if($img == null) { print "<center>no results found</center>"; } 

i don't know how use mysql_num_rows (which i've seen popular solution around site), returns error , i'm thinking doesn't work mysql_fetch_object($sql) ? , don't think this: $img = $result->img; work mysql_num_rows either.

i'm trying find way without having modify inside brackets, ones outside.


when "not working", mean doesn't show message supposed show if results not found. i've tested if($img != null) { print "<center>no results found</center>"; } , works fine, shows message. doesn't seem work other way, , i'm confused.

the following work:

$sql = mysql_query("select * cover match(keyword,description,categories) against('$search_key' in boolean mode) order id desc limit $from , $perpage"); if(mysql_num_rows($sql) > 0) {     $i=1;     while($result = mysql_fetch_object($sql))      {         $keyword = $result->keyword;         $img = $result->img;         $description = $result->description;          if($img != null)          {              this;             if($i==2)              {                  require_once(dirname(__file__).'/page.php');              }             $i++;          }     } } else {      print "<center>no results found</center>";  } 

i see no reason why want store values $result separate variables when can use $result->keyword directly.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -