thefollower Posted October 31, 2007 Share Posted October 31, 2007 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 More sharing options...
ToonMariner Posted October 31, 2007 Share Posted October 31, 2007 if (@mysql_num_rows($GetCommercial) == 0) { // do new loop } else { // do you present loop } Link to comment https://forums.phpfreaks.com/topic/75521-query-with-while-loop/#findComment-382044 Share on other sites More sharing options...
Orio Posted October 31, 2007 Share Posted October 31, 2007 <?php if(mysql_num_rows($GetCommercial) != 0) //regular loop else //No results loop ?> Orio. Link to comment https://forums.phpfreaks.com/topic/75521-query-with-while-loop/#findComment-382046 Share on other sites More sharing options...
thefollower Posted October 31, 2007 Author Share Posted October 31, 2007 How come one had a @ symbol before it and the other does not ? whats the difference? Link to comment https://forums.phpfreaks.com/topic/75521-query-with-while-loop/#findComment-382047 Share on other sites More sharing options...
Orio Posted October 31, 2007 Share Posted October 31, 2007 @ suppresses error messages... See this for more info. Basically it's not needed (and not recommended by php...) but it's up to you if you want to use it. Orio. Link to comment https://forums.phpfreaks.com/topic/75521-query-with-while-loop/#findComment-382051 Share on other sites More sharing options...
ToonMariner Posted October 31, 2007 Share Posted October 31, 2007 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..... Link to comment https://forums.phpfreaks.com/topic/75521-query-with-while-loop/#findComment-382053 Share on other sites More sharing options...
cooldude832 Posted October 31, 2007 Share Posted October 31, 2007 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 More sharing options...
ToonMariner Posted October 31, 2007 Share Posted October 31, 2007 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.