kirkh34 Posted April 27, 2011 Share Posted April 27, 2011 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; Quote Link to comment https://forums.phpfreaks.com/topic/234809-timeout-because-of-for-loop/ Share on other sites More sharing options...
saurabhx Posted April 27, 2011 Share Posted April 27, 2011 Why don't you just use an array instead of $row_1, $row_2.... An array is much more flexible and php offers a great deal of ways to manipulate functions. With arrays, you can write $row[$i] = 1; Quote Link to comment https://forums.phpfreaks.com/topic/234809-timeout-because-of-for-loop/#findComment-1206708 Share on other sites More sharing options...
kirkh34 Posted April 27, 2011 Author Share Posted April 27, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/234809-timeout-because-of-for-loop/#findComment-1206710 Share on other sites More sharing options...
Pikachu2000 Posted April 27, 2011 Share Posted April 27, 2011 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; } } Quote Link to comment https://forums.phpfreaks.com/topic/234809-timeout-because-of-for-loop/#findComment-1206715 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.