charonx3 Posted January 2, 2010 Share Posted January 2, 2010 I'm working on a script that executes a search of my database and displays the results of the search.... i have the search and results part working.... what i can't figure out is how to include a message in case the results are not in my database.... if someone searches for something not in my DB i need to print something like "Results not found" on the page and cannot get that to work... here is my script so far <?php $email=$_POST['email']; $con = mysql_connect ("localhost","****","****"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("suspect1_Master", $con); $result = mysql_query("SELECT EMAIL, Date FROM Emails WHERE EMAIL='$email' ORDER BY Date DESC"); $num_rows = mysql_num_rows($result); print "<table width=400 border=1><th>Email</th><th>Date Reported</br>(yyyy-mm-dd)</th>\n"; while ($get_info = mysql_fetch_row($result)){ print "<tr>\n"; foreach ($get_info as $field) print "\t<td><center><font face=arial size=1 />$field</font></center></td>\n"; print "</tr>\n"; } print "</table>\n"; ?> Link to comment https://forums.phpfreaks.com/topic/186893-help-adding-results-not-found-to-a-search-script/ Share on other sites More sharing options...
The Little Guy Posted January 2, 2010 Share Posted January 2, 2010 <?php $email=$_POST['email']; $con = mysql_connect ("localhost","****","****"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("suspect1_Master", $con); $result = mysql_query("SELECT EMAIL, Date FROM Emails WHERE EMAIL='$email' ORDER BY Date DESC"); $num_rows = mysql_num_rows($result); if($num_rows > 0){ print "<table width=400 border=1><th>Email</th><th>Date Reported</br>(yyyy-mm-dd)</th>\n"; while ($get_info = mysql_fetch_row($result)){ print "<tr>\n"; foreach ($get_info as $field) print "\t<td><center><font face=arial size=1 />$field</font></center></td>\n"; print "</tr>\n"; } print "</table>\n"; }else{ echo "<h1>No Results Found</h1>"; } ?> Link to comment https://forums.phpfreaks.com/topic/186893-help-adding-results-not-found-to-a-search-script/#findComment-986968 Share on other sites More sharing options...
charonx3 Posted January 2, 2010 Author Share Posted January 2, 2010 Thank you so much... you solved one of the last bugs i had to work out... thank you Link to comment https://forums.phpfreaks.com/topic/186893-help-adding-results-not-found-to-a-search-script/#findComment-986971 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.