Page 1 of 1

Echo error line

Posted: Thu Apr 10, 2008 4:43 pm
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! :)

Re: Echo error line

Posted: Thu Apr 10, 2008 4:53 pm
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
}

Re: Echo error line

Posted: Thu Apr 10, 2008 5:14 pm
by khushbush
EXCELLENT!! Thank you soooooooooooo much!! :D