dbase search wont return error
hello-
i have the following php search a database, and everything works fine except if no records are are found i just end up with a blank page.
i want an error to be written to the page saying that no records were found or something.
<?php
$query = \"SELECT property0202.apn, property0202.lastname,
property0202.streetnum, property0202.street,
exclude2002.apn FROM property0202, exclude2002
WHERE property0202.apn LIKE '$apn%'
AND property0202.streetnum LIKE '$streetnum%'
AND property0202.street LIKE '$street%'
AND property0202.lastname LIKE '$lastname%'
AND property0202.apn = exclude2002.apn
ORDER BY property0202.apn, property0202.lastname,
property0202.streetnum, property0202.street\";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array ($result)) {
sprintf (
\"<table>
<tr>
<td>APN</td>
<td>LAST NAME</td>
<td>STREET NUMBER</td>
<td>STREET NAME</td>
</tr>
<tr>
<td> %s </td>
<td> %s </td>
<td> %s </td>
<td> %s </td>
</tr></table>\n\",
$row[0], $row[1], $row[2], $row[3]);
}
?>
nike_guy_man posted this at 22:46 — 11th June 2002.
They have: 840 posts
Joined: Sep 2000
Here, this should work
<?php
$query = \"SELECT property0202.apn, property0202.lastname,
property0202.streetnum, property0202.street,
exclude2002.apn FROM property0202, exclude2002
WHERE property0202.apn LIKE '$apn%'
AND property0202.streetnum LIKE '$streetnum%'
AND property0202.street LIKE '$street%'
AND property0202.lastname LIKE '$lastname%'
AND property0202.apn = exclude2002.apn
ORDER BY property0202.apn, property0202.lastname,
property0202.streetnum, property0202.street\";
$result = mysql_query($query) or die(mysql_error());
$num = mysql_num_rows($result);
if ($num > 0) {
while ($row = mysql_fetch_array ($result)) {
sprintf (
\"<table>
<tr>
<td>APN</td>
<td>LAST NAME</td>
<td>STREET NUMBER</td>
<td>STREET NAME</td>
</tr>
<tr>
<td> %s </td>
<td> %s </td>
<td> %s </td>
<td> %s </td>
</tr></table>\n\",
$row[0], $row[1], $row[2], $row[3]);
}
} else {
print \"No Records Found\";
}
?>
That should work
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.