Echo error line

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
khushbush
Forum Commoner
Posts: 99
Joined: Tue Mar 11, 2008 11:50 am

Echo error line

Post by khushbush »

How can I get this piece of code to show the error line at the bottom of the code fragment when the conditions of the SELECT query are not met? I've tried various combinations between $result and $row and nothing seems to work...

Code: Select all

 
<?
if ($_POST['propertyType']=="Flat" && $_POST['postcode']){
$result = mysql_query("SELECT * FROM property WHERE propertyType = 'Flat' AND propertyArea = '$_POST[postcode]' ORDER BY 'propertyID' ASC");
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
?>
 
<tr>
<td>
<font face="Arial" color="#0B3A62">
<?
// Echo them out
   echo "<a href=\"searchprocess.php?id=$row[propertyID]\">$row[propertyType]". ", £". $row[propertyPrice];
   }
   }
 
   ?>
</a>
</font>
</tr>
</td>
 
<br>
<br>
<p>
<font face="Arial" color="#0B3A62">
<?
// If there are no records returned, tell the user
if(empty($row)){
echo "There are no records returned for your search query.";
}
?>
 
Any help would be much appreciated!! Thanks! :)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Echo error line

Post by John Cartwright »

Use mysql_num_rows() to check if any rows were returned

Code: Select all

if (mysql_num_rows($result) > 0) //more than 0 rows returned, lets loop data 
{
   while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
   {
 
   }
} 
else 
{
   //no rows returned
}
User avatar
khushbush
Forum Commoner
Posts: 99
Joined: Tue Mar 11, 2008 11:50 am

Re: Echo error line

Post by khushbush »

EXCELLENT!! Thank you soooooooooooo much!! :D
Post Reply