spiceydog Posted July 17, 2008 Share Posted July 17, 2008 I have a simple script that says if mysql_num_rows returns 0 than do something different. Unfortunately it doesn't do anything when mysql_num_rows SHOULD be equalling 0. Here is the relevant part of my code: <?php $recent = "SELECT * FROM messages WHERE user='$user' GROUP BY poster ORDER BY views DESC LIMIT 0, 5"; $result1 = mysql_query($recent) or die(mysql_error()); while ($row = mysql_fetch_array($result1)){ $date = $row['date']; $views = $row['views']; $post = $row['post']; $countresult1 = mysql_num_rows($result1) or die(mysql_error()); if ($countresult1 == '') { echo "$gender hasn't posted anything yet."; } } ?> Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/115181-solved-mysql_num_rows-isnt-returning-anything/ Share on other sites More sharing options...
spiceydog Posted July 17, 2008 Author Share Posted July 17, 2008 Fixed! and for all who care the solution was to stick the if statement and mysql_num_rows above the while loop. Link to comment https://forums.phpfreaks.com/topic/115181-solved-mysql_num_rows-isnt-returning-anything/#findComment-592271 Share on other sites More sharing options...
spiceydog Posted July 17, 2008 Author Share Posted July 17, 2008 I really wish I could edit old posts. It would really help. Unfortunately I cant so here is my new problem that derived from my first. So I thought everything worked but it turned out that for some reason my query returns 0 everytime which is weird. Here is my new script: <?php $recent = "SELECT * FROM messages WHERE user='$user' GROUP BY poster ORDER BY date DESC LIMIT 0, 5"; $result1 = mysql_query($recent) or die(mysql_error()); if (mysql_num_rows($result1) == 0) { echo "$gender hasn't posted anything yet."; } else { while ($row = mysql_fetch_array($result1)){ $post = $row['post']; $date = $row['date']; ?> Link to comment https://forums.phpfreaks.com/topic/115181-solved-mysql_num_rows-isnt-returning-anything/#findComment-592279 Share on other sites More sharing options...
Firestorm3d Posted July 17, 2008 Share Posted July 17, 2008 does $user equal anything and if it does, does it exist in the table? Link to comment https://forums.phpfreaks.com/topic/115181-solved-mysql_num_rows-isnt-returning-anything/#findComment-592378 Share on other sites More sharing options...
spiceydog Posted July 18, 2008 Author Share Posted July 18, 2008 It was 5AM.... it was working i just didnt realise there was nothing in the table. Link to comment https://forums.phpfreaks.com/topic/115181-solved-mysql_num_rows-isnt-returning-anything/#findComment-593155 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.