Jump to content

timeout because of for loop


kirkh34

Recommended Posts

I've been getting this error:

 

Fatal error: Maximum execution time of 30 seconds exceeded in... (gives file and line number)

 

I've cut out most of the code in the for loop to narrow it down specifically to the $i variable messing it up somehow...

The 2nd part of the if statement where I try to append the $i variable to the new $row_ variable is causing it to hang like this. 

I want to be able to make 5 new variables... $row_1...$row_2...etc...  but for some reason when I try to append the $i to it, it hangs. and throws that error eventually.  Does anyone know why it does this? Any help is appreciated. Thank you!

 


for ($i=1;$i<6;$i++){

if ($row['bef_remarks' . $i] !=  "Description"){
$row_.$i = 1;

Link to comment
Share on other sites

how dumb of me!! see what happens when you don't code for a few months... that's easy! thanks a lot i feel really dumb but i appreciate the quick response! i still don't understand why it hangs up...oh well the problem is fixed

Link to comment
Share on other sites

I know you have it figured out, but it was hanging because you'd need to do the concatenation of 'row_' and $i first, then use that value as a variable variable. I'm not sure what the technical reason is without digging into the manual, but that was what I had to do to make it work. I'm sure it has to do with the way the concatenation operator works (or doesn't) on variables without assigning the result to a new variable . . .

 

for ( $i=1; $i < 6; $i++ ) {
   if ($row["bef_remarks{$i}"] !=  "Description"){
      $var = "row_$i";
      $$var = 1;
   }
}

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.