tarbender89 Posted August 19, 2010 Share Posted August 19, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/211191-no-results-to-search-query/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 19, 2010 Share Posted August 19, 2010 mysql_num_rows Quote Link to comment https://forums.phpfreaks.com/topic/211191-no-results-to-search-query/#findComment-1101281 Share on other sites More sharing options...
tarbender89 Posted August 19, 2010 Author Share Posted August 19, 2010 Ah! Of course! Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/211191-no-results-to-search-query/#findComment-1101436 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.