Jump to content

while loop, not working


leeming

Recommended Posts

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
Link to comment
Share on other sites

[!--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
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.