johann75 Posted March 10, 2011 Share Posted March 10, 2011 Hello, I am new in php and have made only little so fare. I am trying to make a script, but the script stops. I dont know how loops work. <?php $lenkzeit = 4.5; $lenkunter = 1; $ruhezeit1 = 11; $ruhezeit2 = 9; $stunden1 = 0; $km = 1000; $kmh = 80; $stunden0 = $km/$kmh; $stunden01 = $stunden0; while ($stunden01 > $lenkzeit){ $stunden1 = $stunden1 + $lenkzeit + 1; $stunden01 = $stunden01 - $lenkzeit; //Stops here if ($stunden01 > $lenkzeit) { $stunden1 = $stunden1 + $lenkzeit + $ruhezeit; $stunden01 = $stunden01 - $lenkzeit; } } if ($stunden01 < $lenkzeit) { $srunden1 = $stunden1 + $stunden01; $stunden01 = 0; } echo $srunden1; ?> Quote Link to comment Share on other sites More sharing options...
aabruzzese Posted March 10, 2011 Share Posted March 10, 2011 A typical loop: $a = 1; $b = 99 while ($a <= $b): echo $a; $a++; endwhile; You don't seem to have an endwhile statement in your loop. I would suggest doing a little reading on the web. ie: google --- While Loops in PHP and you will find 10000 examples if not more. Angelo Quote Link to comment Share on other sites More sharing options...
TOA Posted March 10, 2011 Share Posted March 10, 2011 You don't seem to have an endwhile statement in your loop. I would suggest doing a little reading on the web. ie: google --- While Loops in PHP and you will find 10000 examples if not more. Angelo The OP's form is correct also. See here Add these lines to the beginning of your script and tell us the error ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment Share on other sites More sharing options...
johann75 Posted March 11, 2011 Author Share Posted March 11, 2011 Thank you DevilsAdvocate. There was one error. The variable $ruhezeit should be $ruhezeit1. The while loop is working now, but when the while is false, the rest of the script is not running, the last IF. When the while is false, is jumps right to the ECHO without working through the last IF. Quote Link to comment Share on other sites More sharing options...
aabruzzese Posted March 11, 2011 Share Posted March 11, 2011 You don't seem to have an endwhile statement in your loop. I would suggest doing a little reading on the web. ie: google --- While Loops in PHP and you will find 10000 examples if not more. Angelo The OP's form is correct also. See here I just like to see fully qualified and expanded code, I am not one for shortform even if it is accepted. Add these lines to the beginning of your script and tell us the error ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment Share on other sites More sharing options...
TOA Posted March 11, 2011 Share Posted March 11, 2011 When the while is false, is jumps right to the ECHO without working through the last IF. That would mean the condition in the if isn't being met. I have no idea what language that is or what those are supposed to mean so that's as much as I can tell you Quote Link to comment Share on other sites More sharing options...
Mahngiel Posted March 11, 2011 Share Posted March 11, 2011 That would mean the condition in the if isn't being met. I have no idea what language that is or what those are supposed to mean so that's as much as I can tell you I think that's a countdown to World War 3 Quote Link to comment 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.