Ramtree Posted August 6, 2009 Share Posted August 6, 2009 i have a page where the user types in what he wants to search for. then there will a code where it fetches the results from the database base on what the user wants to search for. SELECT ath_id_no, name, gender, photo, country, flag, sport, COUNT(ath_id) FROM athlete JOIN vote ON athlete.ath_id_no= vote.ath_id AND sport='$_POST[filter_sport]' GROUP BY ath_id if the user tries to search for something that doesn't exist in the database, i want to display something like "no search results found" i was thinking of something like while($row=mysql_fetch_array($results)) { if(empty($row['name'])) { echo "no search results found"; } else { echo "<td>" . $row['name'] . "</td>"; } } this doesn't work... i thought i could check if $row['name'] is empty, since nothing is displayed on the table when the user tries to search for something that does not exist in the database. anyone has any idea how to do this? Quote Link to comment Share on other sites More sharing options...
Zepo. Posted August 6, 2009 Share Posted August 6, 2009 Something like this should work. $results = mysql_query(" SELECT ath_id_no, name, gender, photo, country, flag, sport, COUNT(ath_id) FROM athlete JOIN vote ON athlete.ath_id_no= vote.ath_id AND sport='$_POST[filter_sport]' GROUP BY ath_id "); if (mysql_num_rows($result)){ while($row=mysql_fetch_array($results)){ echo "<td>" . $row['name'] . "</td>"; } }else{ echo 'No results were found.'; } Quote Link to comment 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.