Jump to content

help adding "results not found" to a search script


charonx3

Recommended Posts

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"; 
?>

 

 

<?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>";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.