I have a MYsql database of burial records and when you search for the person it returns Name, block and plot where buried and date of birth and death. For some of the records there is no date for either the birth or death in those cases I would like it to show "Unknown" in the field. Any suggestions on how this would work where if the results for the field are empty it echos Unknown. Tried a few different things but can't seem to figure it out. Here is the code that was created with the help of the people here:
<?php
include("admin.php");
$error_msg = '';
$fname = '';
$lname = '';
if (isset($_POST['first']) || isset($_POST['last']))
{
//User submitted a search query
$fname = trim($_POST['first']);
$lname = trim($_POST['last']);
if(empty($lname))
{
//No last name entered
$validationError = "Please enter a last name";
}
else
{
//Perform the database search
mysql_connect("antondad.db.4161444.hostedresource.com", $username, $password);
@mysql_select_db($database) or die( "Unable to select database");
$sql_fname = mysql_real_escape_string($fname);
$sql_lname = mysql_real_escape_string($lname);
$query="SELECT block, plot, first, last, birth, death
FROM burial_records
WHERE last LIKE '{$sql_lname}' AND first LIKE '%{$sql_fname}%'";
if ($last == "")
$result=mysql_query($query);
if(!$result)
{
$error_msg = "Database error occured.";
}
elseif(mysql_num_rows($result)==0)
{
$error_msg = "Sorry, no results found.";
}
else
{
$headResults .= " <th><font face=\"Arial, Helvetica,bold, sans-serif\">Block</font></th>\n";
$headResults .= " <th><font face=\"Arial, Helvetica, sans-serif\">Plot</font></th>\n";
$headResults .= " <th><font face=\"Arial, Helvetica, sans-serif\">First Name</font></th\n>";
$headResults .= " <th><font face=\"Arial, Helvetica, sans-serif\">Last Name</font></th>\n";
$headResults .= " <th><font face=\"Arial, Helvetica, sans-serif\">Born</font></th>\n";
$headResults .= " <th><font face=\"Arial, Helvetica, sans-serif\">Died</font></th>\n";
$recordResults = '';
while ($record = mysql_fetch_assoc($result))
{
$recordResults .= " <tr>\n";
$recordResults .= " <td><font face=\"Arial, Helvetica, sans-serif\">{$record['block']}</font></td>\n";
$recordResults .= " <td><font face=\"Arial, Helvetica, sans-serif\">{$record['plot']}</font></td>\n";
$recordResults .= " <td><font face=\"Arial, Helvetica, sans-serif\">{$record['first']}</font></td>\n";
$recordResults .= " <td><font face=\"Arial, Helvetica, sans-serif\">{$record['last']}</font></td>\n";
$recordResults .= " <td><font face=\"Arial, Helvetica, sans-serif\">{$record['birth']}</font></td>\n";
$recordResults .= " <td><font face=\"Arial, Helvetica, sans-serif\">{$record['death']}</font></td>\n";
$recordResults .= " </tr>\n";
}
}
mysql_close();
}
}
?>