MySQL Forums
Forum List  »  PHP

Basic PHP Question - No results found
Posted by: Keith Mundrick
Date: July 28, 2005 08:08AM

I'm using the following code to spit out some info from a database. Users enter their street number and street name and their zoning information is given to them.

I want to have it display "no results found" or whatever if there are no perfect matches. How do I do this? Thanks!

My code:

$link = mysql_connect('localhost', 'xxxxxxxxx', 'xxxxxxx')
or die('Could not connect: ' . mysql_error());
mysql_select_db('land_info_search') or die('Could not select database.');

// Retrieve all the data from the table

$result = mysql_query("SELECT * FROM land_info WHERE (ADDR_NUM = '$addy')")
or die(mysql_error());

// store the record of the table into $row

$row = mysql_fetch_array( $result );

// Print out the contents of the entry
print $query;
echo "<table width='450' border='0'>";
echo "<font face='Arial' size='2'>";
echo "<tr>";
echo "<td colspan='2'></td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan='2'><font face='Arial' size='2'>Zoning information for $addy $street</font></td>";
echo "</tr>";
echo "<tr>";
echo "<td>&nbsp;</td>";
echo "<td>&nbsp;</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Zoning Classification:</td>";
echo "<td>$row[ZONE_CLASS]</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Fire District:</td>";
echo "<td>$row[FIRE_DIST]</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Police District: </td>";
echo "<td>$row[POLICE_DIST]</td>";
echo "</tr>";
echo "<tr>";
echo "<td>&nbsp;</td>";
echo "<td>&nbsp;</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Voting Precinct: </td>";
echo "<td>$row[PRECNT_CH]</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Polling Place: </td>";
echo "<td>$row[PLNG_PLC]</td>";
echo "</tr>";
echo "<tr>";
echo "<td>&nbsp;</td>";
echo "<td>$row[PLNG_ADDR]</td>";
echo "</tr>";
echo "<tr>";
echo "<td>&nbsp;</td>";
echo "<td>$row[PLNG_CITY]</td>";
echo "</tr>";
echo "<tr>";
echo "<td>&nbsp;</td>";
echo "<td>&nbsp;</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Elementary School District: </td>";
echo "<td>$row[ELEM_FULLNAME]</td>";
echo "</tr>";
echo "<tr>";
echo "<td>&nbsp;</td>";
echo "<td>$row[ELEM_ADDR]</td>";
echo "</tr>";
echo "<tr>";
echo "<td>&nbsp;</td>";
echo "<td>$row[ELEM_CITY], IL $row[ELEM_ZIP]</td>";
echo "</tr>";
echo "<tr>";
echo "<td>&nbsp;</td>";
echo "<td>$row[ELEM_PHONE]</td>";
echo "</tr>";
echo "<tr>";
echo "<td>&nbsp;</td>";
echo "<td>$row[ELEM_URL]</td>";
echo "</tr>";
echo "<tr>";
echo "<td>&nbsp;</td>";
echo "<td>&nbsp;</td>";
echo "</tr>";
echo "<tr>";
echo "<td>High School District: </td>";
echo "<td>$row[HIGH_FULLNAME]</td>";
echo "</tr>";
echo "<tr>";
echo "<td>&nbsp;</td>";
echo "<td>$row[HIGH_ADDR]</td>";
echo "</tr>";
echo "<tr>";
echo "<td>&nbsp;</td>";
echo "<td>$row[HIGH_CITY], IL $row[HIGH_ZIP]</td>";
echo "</tr>";
echo "<tr>";
echo "<td>&nbsp;</td>";
echo "<td>$row[HIGH_PHONE]</td>";
echo "</tr>";
echo "<tr>";
echo "<td>&nbsp;</td>";
echo "<td>$row[HIGH_URL]</td>";
echo "</tr>";
echo "<tr>";
echo "<td>&nbsp;</td>";
echo "<td>&nbsp;</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Garbage Collection Day: </td>";
echo "<td>$row[GARBAGE_DAY]</td>";
echo "</tr>";
echo "</font>";
echo "</table>";


// Closing connection
mysql_close($link);

Options: ReplyQuote


Subject
Written By
Posted
Basic PHP Question - No results found
July 28, 2005 08:08AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.