Jump to content

"No Results" to search query.


tarbender89

Recommended Posts

Back again!  This forum was so helpful the last time I had a question (a whopping couple days ago, haha) that I'm wondering if you guys can help me out once again.

 

My server version is 5.1.

 

What I'm trying to do is add a line of code that will display "No results found."  when the database returns no results after a search.

 

Here's the current code for my search:

mysql_connect ("localhost", "tarb89_admin", "leccums")  or die (mysql_error());
mysql_select_db ("tarb89_ausus");
$term = $_POST['term'];
$sql = mysql_query("SELECT `id`, `character_name`, `breed`, `gender`, `base_color`, `markings`, `genetics`, `sire`, `dam`, `other`, `player` FROM characters WHERE `player` LIKE '%$term%' OR `character_name` LIKE '%$term%' OR `id` LIKE '$term'") or die ('Error: '.mysql_error ());
while ($row = mysql_fetch_array($sql)){
echo '<br/><h2>'.$row['character_name'];
echo '</h2> ID Number: '.$row['id'];
echo '<br/>'.$row['gender'];
echo '<br/>'.$row['breed'];
echo '<br/>'.$row['base_color'];
echo '<br/>'.$row['markings'];
echo '<br/>'.$row['genetics'];
echo '<br/>'.$row['sire'];
echo ' x '.$row['dam'];
echo '<br/>'.$row['other'];
echo '<br/>'.$row['breed'];
echo '<br/>Played by '.$row['player'];
echo '<br/><br/>';
}

 

I swear I've researched and researched this, but everything I  try ends up in a MySQL error.  The code posted above works fine and will display the correct results that were searched for; but if there were no results found in the database, it simply returns nothing.  I'd like it to return "No results found." kinda thing.

 

Thanks again!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.