wejofost Posted January 5, 2008 Share Posted January 5, 2008 I have a HTML form with a series of 7 check boxes that have been passed to a php page where for each of the check boxes "ticked" I wish to increment a total by a different value depending on the check box ticked. I have a test page ( code below ) which proves that the check boxes have been ticked and I am using a 'while' statement to check if the box has been ticked and if so increment a total. PROBLEM is that the while statement runs continously when true. I expected it to go through once and then step on to the next statement but it loops for ever!. After a successful while statement ( that is the condition is true ) do I have to 'disable' the value ( make the condition false )? Help! <?php $newline = "<br>"; echo " Start of Living Room Selection. " ; echo $newline; echo " Total so far "; $lrtotal = 25000; echo $lrtotal; echo $newline; echo "Switch value = "; echo ($_POST['option1']); echo $newline; echo ($_POST['option2']); echo $newline; echo ($_POST['option3']); echo $newline; echo ($_POST['option4']); echo $newline; echo ($_POST['option5']); echo $newline; echo ($_POST['option6']); echo $newline; echo ($_POST['option7']); echo $newline; $TwoSeaterSofa = 1.00; $ThreeSeaterSofa = 9.00; echo "Twoseater literal is "; echo $TwoSeaterSofa; echo $newline; echo "Threeseater literal is "; echo $ThreeSeaterSofa; echo $newline; while (($_POST['option1'])== true) {echo ($_POST['option1']); $lrtotal = $lrtotal + $TwoSeaterSofa; echo $lrtotal; echo $newline; } while (($_POST['option2'])== true) {echo ($_POST['option2']); $lrtotal = $lrtotal + $ThreeSeaterSofa; echo $lrtotal; echo $newline; } // 5 more while statementsfor $_POST [option3 to 7 ] in here. echo " Total for living room "; echo $lrtotal; echo $newline; ?> Quote Link to comment https://forums.phpfreaks.com/topic/84574-solved-continously-looping-while-statements/ Share on other sites More sharing options...
trq Posted January 5, 2008 Share Posted January 5, 2008 You'll want to use a foreach. <?php foreach ($_POST['option1'] as $opt) { echo $opt; $lrtotal += $TwoSeaterSofa; echo $lrtotal; echo $newline; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84574-solved-continously-looping-while-statements/#findComment-430965 Share on other sites More sharing options...
wejofost Posted January 5, 2008 Author Share Posted January 5, 2008 O.K. Thank you. Now working OK. Quote Link to comment https://forums.phpfreaks.com/topic/84574-solved-continously-looping-while-statements/#findComment-431331 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.