leeming Posted February 28, 2006 Share Posted February 28, 2006 this is the 2nd time ive had this bug, and cant figgure it out...basicly its a while loop like this[code]$sql = mysql_query("SELECT * FROM members"); while($members = mysql_fetch_array($sql)) { ~random code~ }[/code]yet when i run this code, it only does 1 loop. even when there is more records to loop through.i have put 'or die()' messagses on the end of the sql string, and nothing... i have even printed the data in the loop (thus how i know there is only 1 loop) so i tried doing this...[code]$sql = mysql_query("SELECT * FROM members"); while($members = mysql_fetch_array($sql)) { print $num; $num++; }[/code]which shows numbers 1-(number of max records in my table)so this shows the loop is working.. but only when my code sint inside it?the only placves in my code inside this while loop is at sql queries, which have an error string inside the die() function, so that cant be why the code is stopping?any way im lost to what could be wrong Quote Link to comment https://forums.phpfreaks.com/topic/3756-while-loop-not-working/ Share on other sites More sharing options...
AV1611 Posted February 28, 2006 Share Posted February 28, 2006 Please tell me what this results in:[code]$sql = mysql_query("SELECT count(*) as COUNT FROM members"); IF($members = mysql_fetch_array($sql)) { echo $members['COUNT']; }[/code] Quote Link to comment https://forums.phpfreaks.com/topic/3756-while-loop-not-working/#findComment-13037 Share on other sites More sharing options...
leeming Posted February 28, 2006 Author Share Posted February 28, 2006 [!--quoteo(post=350256:date=Feb 28 2006, 04:25 PM:name=AV1611)--][div class=\'quotetop\']QUOTE(AV1611 @ Feb 28 2006, 04:25 PM) [snapback]350256[/snapback][/div][div class=\'quotemain\'][!--quotec--]Please tell me what this results in:[code]$sql = mysql_query("SELECT count(*) as COUNT FROM members"); IF($members = mysql_fetch_array($sql)) { echo $members['COUNT']; }[/code][/quote]i get 111 Quote Link to comment https://forums.phpfreaks.com/topic/3756-while-loop-not-working/#findComment-13042 Share on other sites More sharing options...
kenrbnsn Posted February 28, 2006 Share Posted February 28, 2006 Please post the code that doesn't work. It sounds like you have a something in your code that is causing the loop to exit early. Maybe you're redefining the variable $members?Ken Quote Link to comment https://forums.phpfreaks.com/topic/3756-while-loop-not-working/#findComment-13072 Share on other sites More sharing options...
AV1611 Posted February 28, 2006 Share Posted February 28, 2006 Well, you should be getting that may row returns. Because you are not, you need to post your script, so we can see why it's not working...[!--quoteo(post=350263:date=Feb 28 2006, 11:31 AM:name=leeming)--][div class=\'quotetop\']QUOTE(leeming @ Feb 28 2006, 11:31 AM) [snapback]350263[/snapback][/div][div class=\'quotemain\'][!--quotec--]i get 111[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/3756-while-loop-not-working/#findComment-13075 Share on other sites More sharing options...
leeming Posted February 28, 2006 Author Share Posted February 28, 2006 this is one of the 2 codes that dont work, but with the same problem... but this is the simplist to understand, without knowning the rest of my code$hour and $minute are just quick ref for date(i) and date(H)[code] $findnum1 = mysql_query("select * from revs WHERE min='$minute' AND hr='$hour'")or die('<B>ERROR</B>: Unknown error, array for rev number<BR>Please report this to an admin: '.mysql_error()); while($findnum = mysql_fetch_array($findnum1)) //all members who are getting revived this min + hour { $heal = mysql_fetch_array(mysql_query("select * from member WHERE mid='$findnum[userid]'")); if($heal[hp]<$heal[max_hp]) { mysql_query("update member set `hp`=`max_hp` WHERE mid='$heal[mid]'")or die('<B>ERROR</B>: Unknown error, update hp<BR>Please report this to an admin: '.mysql_error()); } if($hour < "06" && $hour >= "00") { $starthour="06"; } elseif($hour < "12" && $hour >= "06") { $starthour="12"; } elseif($hour < "18" && $hour >= "12") { $starthour="18"; } elseif($hour >= "18") { $starthour="00"; } mysql_query("update revs set min='".rand(1,59)."', hr='".rand($starthour, ($starthour + 5))."' WHERE userid='$heal[mid]'")or die('<B>ERROR</B>: Unknown error, updating random revive timer<BR>Please report this to an admin: '.mysql_error()); } [/code]this is basicly a part of code for my game, it gives members full hp 4 times a day, but issues it at random times ( randomly between 00:00-06:00/ 06:00-12:00/12:00-18:00/18:00-00:00 , so basicly every 6 hours) Quote Link to comment https://forums.phpfreaks.com/topic/3756-while-loop-not-working/#findComment-13080 Share on other sites More sharing options...
leeming Posted March 3, 2006 Author Share Posted March 3, 2006 i am still in need of help for this. Quote Link to comment https://forums.phpfreaks.com/topic/3756-while-loop-not-working/#findComment-13953 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.