plutomed Posted February 17, 2007 Share Posted February 17, 2007 while($blist = mysql_fetch_array($banlist)) { if(mysql_num_rows($banlist)==0){ echo "<td colspan=\"2\">No IPs in the database</td>"; //<-----------this bit here } else { echo "<td>" . $blist['ips'] . "</td>"; echo "<td><a href=\"admincp.php?do=removeip&ip=" . $blist['ips'] . "\">Remove</a></td>"; } } this bit of code doesnt seem to work any ideas ??? the second bit after the else works but the if bit dont ??? Quote Link to comment https://forums.phpfreaks.com/topic/38928-solved-mysql_num_rows/ Share on other sites More sharing options...
JJohnsenDK Posted February 17, 2007 Share Posted February 17, 2007 try this: while($blist = mysql_fetch_array($banlist)) { $banlist2 = mysql_num_rows($banlist); if($banlist2==0){ echo "<td colspan=\"2\">No IPs in the database</td>"; //<-----------this bit here } else { echo "<td>" . $blist['ips'] . "</td>"; echo "<td><a href=\"admincp.php?do=removeip&ip=" . $blist['ips'] . "\">Remove</a></td>"; } } Quote Link to comment https://forums.phpfreaks.com/topic/38928-solved-mysql_num_rows/#findComment-187211 Share on other sites More sharing options...
wildteen88 Posted February 17, 2007 Share Posted February 17, 2007 You should check the returned rows before going into the while loop. So you should do this: if(mysql_num_rows($banlist) < 1) { echo '<td colspan="2">No IPs in the database</td>'; } else { while($blist = mysql_fetch_array($banlist)) { echo '<td>' . $blist['ips'] . '</td>'; echo '<td><a href="admincp.php?do=removeip&ip=' . $blist['ips'] . '">Remove</a></td>'; } } Quote Link to comment https://forums.phpfreaks.com/topic/38928-solved-mysql_num_rows/#findComment-187212 Share on other sites More sharing options...
plutomed Posted February 17, 2007 Author Share Posted February 17, 2007 yes thanks wildteen88 it works thanks to all you others aswell Quote Link to comment https://forums.phpfreaks.com/topic/38928-solved-mysql_num_rows/#findComment-187215 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.