kworld Posted May 1, 2010 Share Posted May 1, 2010 Hey all, This bit of code is currently slowing my browser load to the point of this message; Fatal error: Maximum execution time of 60 seconds exceeded. Can anybody help me please its like the loop continues even though its already calcultaed what needs to be done. while(($pricecalc != $dprice)||($pricecalc>$dprice)) { $pricecalc = ($pricecalc-$dprice); } Link to comment https://forums.phpfreaks.com/topic/200405-while-loop-slowing-browser-down/ Share on other sites More sharing options...
Ken2k7 Posted May 1, 2010 Share Posted May 1, 2010 I think you want && and not || because it can be the case that $pricecalc will never equal the value of $dprice so that first part will always remain true. But with just that snippet, I can't say for certain that && is what you should use. Please explain what that loop should do. Link to comment https://forums.phpfreaks.com/topic/200405-while-loop-slowing-browser-down/#findComment-1051677 Share on other sites More sharing options...
kworld Posted May 1, 2010 Author Share Posted May 1, 2010 The || are for an OR operator, It is meant to either be equal or be under the standard price if it goes below the standard price the while loop will stop. The calculations seem to get done correctly and be displayed but only when it has a 60 second time out, i think the loop doesnt want to stop for some reason. Link to comment https://forums.phpfreaks.com/topic/200405-while-loop-slowing-browser-down/#findComment-1051685 Share on other sites More sharing options...
Ken2k7 Posted May 1, 2010 Share Posted May 1, 2010 Yes, but that's not what your code says. It says: Run $pricecalc = ($pricecalc-$dprice); if one of the following is true: 1. $pricecalc != $dprice 2. $pricecalc>$dprice So even if $pricecalc is less than $dprice (meaning #2 will be false), that doesn't mean $pricecalc is equal to $dprice, so since #1 is true, the while loop continues. To do what you want, you probably want this: (if I understand the issue correctly) if ($pricecalc != $dprice) { while ($pricecalc > $dprice) $pricecalc -= $dprice; } Link to comment https://forums.phpfreaks.com/topic/200405-while-loop-slowing-browser-down/#findComment-1051692 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.