HDFilmMaker2112 Posted May 16, 2011 Share Posted May 16, 2011 while($row10000=mysql_fetch_array($result10000)){ $product_id3=$row10000['product_id']; $sql15000="SELECT * FROM $tbl_name WHERE product_id=".$product_id3; $result15000=mysql_query($sql15000); while($row15000=mysql_fetch_array($result15000)){ extract($row15000); if(mysql_num_rows($result15000)==0){ $content='<div class="center">Search found no results.</div>'; } else{ $content.=$product_name; } } } The above does not display the $content variable when there are no rows returned, just comes up with a blank page. Works fine when there are results returned. Quote Link to comment https://forums.phpfreaks.com/topic/236585-mysql_num_rows-not-working/ Share on other sites More sharing options...
jcbones Posted May 16, 2011 Share Posted May 16, 2011 That is how it should work, as the while statement will never run, being that it will return false on row 0. You MUST put the mysql_num_rows() function BEFORE the while statement. Quote Link to comment https://forums.phpfreaks.com/topic/236585-mysql_num_rows-not-working/#findComment-1216233 Share on other sites More sharing options...
Maq Posted May 16, 2011 Share Posted May 16, 2011 That is how it should work, as the while statement will never run, being that it will return false on row 0. You MUST put the mysql_num_rows() function BEFORE the while statement. EDIT: This ^ Quote Link to comment https://forums.phpfreaks.com/topic/236585-mysql_num_rows-not-working/#findComment-1216235 Share on other sites More sharing options...
HDFilmMaker2112 Posted May 16, 2011 Author Share Posted May 16, 2011 That is how it should work, as the while statement will never run, being that it will return false on row 0. You MUST put the mysql_num_rows() function BEFORE the while statement. That's what I figured... was just to lazy to change it to try it myself. EDIT: Just tried it, still a blank page. while($row10000=mysql_fetch_array($result10000)){ $product_id3=$row10000['product_id']; $sql15000="SELECT * FROM $tbl_name WHERE product_id=".$product_id3; $result15000=mysql_query($sql15000); if(mysql_num_rows($result15000)==0){ $content='<div class="center">Search found no results.</div>'; } else{ while($row15000=mysql_fetch_array($result15000)){ extract($row15000); $content.=$product_name; } } } Quote Link to comment https://forums.phpfreaks.com/topic/236585-mysql_num_rows-not-working/#findComment-1216236 Share on other sites More sharing options...
jcbones Posted May 16, 2011 Share Posted May 16, 2011 Cannot help you, as there are many reasons that you would get a blank page. I KNOW that you have all error reporting set on HIGH!!! ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/236585-mysql_num_rows-not-working/#findComment-1216240 Share on other sites More sharing options...
HDFilmMaker2112 Posted May 16, 2011 Author Share Posted May 16, 2011 Well turned on error reporting and all I'm getting is notices that I have an Undefined Index and that the Content variable is undefined (because it's being called but nothing's a signed to it, for whatever reason. The page is actually displayed properly when the keyword exists, just when there are no results returned does it not show anything. Quote Link to comment https://forums.phpfreaks.com/topic/236585-mysql_num_rows-not-working/#findComment-1216245 Share on other sites More sharing options...
jcbones Posted May 16, 2011 Share Posted May 16, 2011 Is your first query executing? Quote Link to comment https://forums.phpfreaks.com/topic/236585-mysql_num_rows-not-working/#findComment-1216249 Share on other sites More sharing options...
HDFilmMaker2112 Posted May 16, 2011 Author Share Posted May 16, 2011 Is your first query executing? Nope, that would be way, the first query is what actually does the search look-up so.... Moved it outside the first while and working perfectly now. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/236585-mysql_num_rows-not-working/#findComment-1216254 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.