Note that there are some explanatory texts on larger screens.

plurals
  1. POMysql_fetch_object() SQL Query (HOW TO: If no results found, display "message" )?
    text
    copied!<p>I've spent hours trying to make this work. No solutions from the search have helped me, so I'm finally asking.</p> <p>What I'm trying to do is: <strong>Display a message if no results are found</strong>.</p> <p>This is what I have, and it is currently not working to my dismay.</p> <pre class="lang-sql prettyprint-override"><code> $sql = mysql_query("SELECT * FROM cover WHERE MATCH(keyword,description,categories) AGAINST('$search_key' in boolean mode) ORDER BY id DESC LIMIT $from , $perPage"); $i=1; while($result = mysql_fetch_object($sql)) { $keyword = $result-&gt;keyword; $img = $result-&gt;img; $description = $result-&gt;description; if($img != null) { DO THIS; if($i==2) { require_once(dirname(__FILE__).'/page.php'); } $i++; } } if($img == null) { print "&lt;center&gt;No Results Found&lt;/center&gt;"; } </code></pre> <p>I don't know how to use <strong>mysql_num_rows</strong> with this (which is what I've seen is the most popular solution around the site), it returns an error and I'm thinking it doesn't work well with <code>mysql_fetch_object($sql)</code> <strong>?</strong> And I don't think this: <code>$img = $result-&gt;img;</code> would work with mysql_num_rows either.</p> <p>I'm just trying to find a way to do this without having to modify anything inside the brackets, just the ones outside.</p> <hr> <p><strong>When I say "NOT WORKING"</strong>, I mean it doesn't show the message that is supposed to show if results are not found. I've tested <code>if($img != null) { print "&lt;center&gt;No Results Found&lt;/center&gt;"; }</code> and it works fine, it shows the message. But it doesn't seem to work the other way, and I'm now just confused.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload