Jump to content

Query with while loop


thefollower

Recommended Posts

I have a query with a while loop but just prior the the while loop i want to check if no rows are found, and if there isn't any rows found then it will load up a different while loop.... but not sure how to do the check to find if theres any rows...

This is what i have:

 

$GetCommercial = mysql_query("SELECT * FROM businesses WHERE Catergory = 'Commercial' AND CityID = '1' AND BusinessType='Food Market'")
or die(mysql_error());
Echo'<div id="bv_" style="position:absolute;left:357px;top:300px;width:150px;height:16px;z-index:3" align="center">
<font style="font-size:13px" color="#FFFFFF" face="Arial"><b><u>Food Markets</u></b></font></div>
<div id="bv_" style="position:absolute;left:221px;top:341px;width:150px;height:16px;z-index:2" align="center">';
while($GetCommercialResult = mysql_fetch_array($GetCommercial)) {
Echo'<font style="font-size:13px" color="#FFFFFF" face="Arial"><b><u></br></br></br>';
Echo $GetCommercialResult['BusinessName'];
Echo'</u></b></font>';
}
Echo '</div>';

Link to comment
https://forums.phpfreaks.com/topic/75521-query-with-while-loop/
Share on other sites

Agreed but I find it useful with num_rows - some servers will throw an error if the number of results is 0 - because they were set up by a 3 year old.....

Um not true

 

Servers will only error if the resource provided is not a valid mysql resource.  Assuming you are on 4.1 +

Link to comment
https://forums.phpfreaks.com/topic/75521-query-with-while-loop/#findComment-382060
Share on other sites

Assuming all manner of thinsg - but I have in the past encountered installations where teh number of rows being 0 it has been evaluated as FALSE and spitting out an error.  These I guess were the little idiosyncrasies of the installations - with a query that was perfectly well formed I might add.

Link to comment
https://forums.phpfreaks.com/topic/75521-query-with-while-loop/#findComment-382397
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.