ajenkins198621 Posted April 10, 2009 Share Posted April 10, 2009 Hello All, I am fairly new to PHP, and am dumbfounded why I cannot get this simple code to work. Anyways, what I am trying to accomplish is to access my mysql database and pull up the records that match a certain "building-type" (it is a real-estate website). I have gotten this part to work, however, I would also like to display a message when no records exist. For some reason, I cannot get this message to appear. Below is the code I am trying to use: <?PHP $buildingtype = urldecode( $_GET['buildingtype'] ); mysql_connect("xxx", "xxx", "xxx") or die(mysql_error()); mysql_select_db("xxx") or die(mysql_error()); $query="SELECT district_name,citytown,listing_price,bedrooms,bathrooms,mls_number,image1 FROM listings WHERE building_type='$buildingtype'"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> <?php for ($i=0; $i<$num; $i++) { $citytown=mysql_result($result,$i,"citytown"); $listing_price=mysql_result($result,$i,"listing_price"); $bedrooms=mysql_result($result,$i,"bedrooms"); $bathrooms=mysql_result($result,$i,"bathrooms"); $mls_number=mysql_result($result,$i,"mls_number"); if ($num[$i]==0) //THIS IS THE PART THAT I JUST CAN'T FIGURE OUT // { echo "<p>I currently have no listings in the district" . $districtname .", however you can search for listings all over the Hawaiin Islands via the Hawaiin Information Service (<a href=http://www.hawaiiinformation.com/research/>http://www.hawaiiinformation.com/research/</a>). Please <a href=/Sites/contact_me.php>contact me</a> if you find any property on any island and I can assist you with any and all of your Hawaiin real-estate Needs. <br /> <br /><strong>Mahalo</stong> </p>"; } else { echo " <table width=\"600\" cellpadding=\"5\"> <tr> <td width=\"200\" height=\"210\" rowspan=\"15\"><div align=\"center\"><img src=http://www.loriburris.com/images/listings/".$mls_number."/".$mls_number."_01.gif width=\"200\" height=\"200\" id=\"".$mls_number."_01.gif\" /></div></td> <td colspan=\"2\"><div align=\"center\"<strong>".$citytown."</strong></div></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td><div align=\"right\"><span class=\"style1\">Location:</span></div></td> <td>".$citytown."</td> </tr> <tr> <td class=\"style1\"><div align=\"right\">Price:</div></td> <td>".$listing_price."</td> </tr> <tr> <td class=\"style1\"><div align=\"right\">Bedrooms:</div></td> <td>".$bedrooms."</td> </tr> <tr> <td class=\"style1\"><div align=\"right\">Bathrooms:</div></td> <td>".$bathrooms."</td> </tr> <tr> <td class=\"style1\"><div align=\"right\">MLS #:</div></td> <td>".$mls_number."</td> </tr> <tr> <td class=\"style1\"><div align=\"right\">Contact:</div></td> <td><a href=/Sites/contact_me.php>Lori Burris</a></td> </tr> <tr> <td class=\"style1\"> </td> <td> </td> </tr> <tr> <td colspan=\"2\" class=\"style1\"><div align=\"center\"> <a href='http://www.loriburris.com/Sites/moreinformation.php?mls_number=".urlencode( $mls_number ) ."'> Click here for more information</a></div></td> </tr> <tr> <td class=\"style1\"> </td> <td> </td> </tr> </table>"; } } ?> Any help would be very appreciated! Link to comment https://forums.phpfreaks.com/topic/153544-php-mysql-identify-when-no-records-exist/ Share on other sites More sharing options...
MatthewJ Posted April 10, 2009 Share Posted April 10, 2009 Just check $num... if it isn't greater than 0, you have nothing. if ($num < 1) Link to comment https://forums.phpfreaks.com/topic/153544-php-mysql-identify-when-no-records-exist/#findComment-806811 Share on other sites More sharing options...
ajenkins198621 Posted April 10, 2009 Author Share Posted April 10, 2009 Thanks, but it is still not working. I tried setting $num<1, but it is still not displaying the message. It may help if I show you what I am working with, Check out: http://www.loriburris.com/Sites/listingsbytype.php?buildingtype=Business (not working) vs. http://www.loriburris.com/Sites/listingsbytype.php?buildingtype=Residential (working). Thanks again. Link to comment https://forums.phpfreaks.com/topic/153544-php-mysql-identify-when-no-records-exist/#findComment-806837 Share on other sites More sharing options...
jackpf Posted April 10, 2009 Share Posted April 10, 2009 mysql_numrows is not a function. mysql_num_rows on the other hand is... Link to comment https://forums.phpfreaks.com/topic/153544-php-mysql-identify-when-no-records-exist/#findComment-806843 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.