karimali831 Posted June 1, 2010 Share Posted June 1, 2010 Hi, Got a problem. For the first one, it will die if no rows. $registered=safe_query("'"); if(!mysql_num_rows($registered)) die(); while($dd=mysql_fetch_array($registered)) { ... } For this one, it does not die if there is no rows and I'm not sure why? When it is under fetch it does not understand or something? $registered=safe_query("'"); while($dd=mysql_fetch_array($registered)) { if(!mysql_num_rows($registered)) die(); ... } I need it under for reasons. what can I do or is there something else I can use so that it will work in the loop? Thank you for help. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 1, 2010 Share Posted June 1, 2010 The second example doesn't make any sense. The loop won't execute if there are no rows returned. What are you trying to do? Ken Quote Link to comment Share on other sites More sharing options...
karimali831 Posted June 1, 2010 Author Share Posted June 1, 2010 There maybe rows and there maybe no rows, rows is checked when the user is logged in. $registered=safe_query("SELECT * FROM ".PREFIX."cup_clans WHERE clanID='".$te['clanID']."' && 1on1='0' && cupID='$cupID'"); But as you say loop won't run if these is no rows then I can't use mysql_num_rows under it? Quote Link to comment Share on other sites More sharing options...
jcbones Posted June 1, 2010 Share Posted June 1, 2010 If the loop doesn't run, then neither does any code inside the loop. Although, in theory you could do. $registered=safe_query("'"); $num = mysql_num_rows($registered); while($dd=mysql_fetch_array($registered)) { if($num == 0) die(); ... } Although, I don't know why you would want to. Quote Link to comment Share on other sites More sharing options...
karimali831 Posted June 1, 2010 Author Share Posted June 1, 2010 Thanks, that's just what I needed. Quote Link to comment Share on other sites More sharing options...
karimali831 Posted June 3, 2010 Author Share Posted June 3, 2010 When I use if($num == 0) die(); above fetch it dies but below fetch it doesn't. So this doesn't work? Quote Link to comment Share on other sites More sharing options...
andrewgauger Posted June 3, 2010 Share Posted June 3, 2010 Unrelated but always put variables like: $te['clanID'] as: {$te['clanID']} inside strings. The reason the second doesn't die is because the while is never met. if you type in: while(false) {echo "do something";} the code will never execute. You can't fetch from 0 rows. Quote Link to comment 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.