Forum Moderators: coopster
if(isset($_POST['findcust']) && !empty($_POST['findcust']))
{
$surname = $_POST["findcust"];
$sql = "SELECT * FROM customer WHERE lastname LIKE '".$surname. "'";
$result=mysql_query($sql);
$db_field = mysql_fetch_assoc($result);
foreach($db_field as $key => $value) {echo "Key is: ".$key. " <i>Value is:".$value. "</i><br/>";}
?echo "<script type=\"text/javascript\">document.getElementById('findcust').value = ".$_POST[findcust]'. ";</script>";"
$count=mysql_num_rows($result);
if ($count == 0)
{
echo "<script type=\"text/javascript\"> alert('No record was found with name ". $surname . "');</script>";
}
else if($count)
{
$content = "<table id=\"resultset\">";
while ($db_field = mysql_fetch_assoc($result))
{
$content .= "<tr>";
$content .= "<td>".$db_field["firstname"]."</td>";
$content .= "<td>".$db_field["lastname"]."</td>";
$content .= "<td>".$db_field['address1]."</td>";
$content .= "<td>".$db_field['address2']."</td>";
$content .= "<td>".$db_field['county']."</td>";
$content .= "<td>".$db_field['home_phone']."</td>";
}
$content .= "</table>";
echo "<script type=\"text/javascript\">document.getElementById('servcont').innerHTML = ".$content. ";</script>";
}
<div id="servcont">
<?php
// As mentioned, the code operations don't have to take place in the div,
// and can be at the top, but just for example . . .
$count=mysql_num_rows($result);
if ($count == 0) {
echo "<p>No record was found with name $surname</p>";
}
// If it's not 0, it must be greater, right?
else {
$content = null; // To squelch concatenation warnings
while ($db_field = mysql_fetch_assoc($result)) {
$content .= "<tr>
<td>".$db_field["firstname"]."</td>
<td>".$db_field["lastname"]."</td>
<td>".$db_field['address1]."</td>
<td>".$db_field['address2']."</td>
<td>".$db_field['county']."</td>
<td>".$db_field['home_phone']."</td>
</tr>"; // you missed closing tr
}
echo "<table id=\"resultset\">$content</table>";
}
?>
</div>