hyster Posted March 20, 2011 Share Posted March 20, 2011 im having problems with the count in the if statment. its only counting the last value _posted. im missing something really simple but i can not see it. help please. <?php $count= $_GET['seatco']; for ($i=1; $i<=$count; $i++) { $ticket = $_POST['tick_com'.$i]; echo "tickets: ".$ticket; echo "<br>"; $adult= "0"; $child= "0"; $concession = "0"; if ($ticket =="adult") { $adult++; } elseif($ticket == "child"){ $child++; } elseif($ticket =="concession"){ $conc++; } else{ echo "no";} } } echo "Adult".$adult; echo "Child".$child; echo "Concession".$conc; ?> Quote Link to comment https://forums.phpfreaks.com/topic/231179-if-statment-inside-a-for-loop/ Share on other sites More sharing options...
gristoi Posted March 20, 2011 Share Posted March 20, 2011 Hi, try moving the starting counts out of the loop <?php $count= $_GET['seatco']; $adult= 0; $child= 0; $concession = 0; for ($i=1; $i<=$count; $i++) { $ticket = $_POST['tick_com'.$i]; echo "tickets: ".$ticket; echo "<br>"; if ($ticket =="adult") { $adult++; } elseif($ticket == "child"){ $child++; } elseif($ticket =="concession"){ $conc++; } else{ echo "no";} } } echo "Adult".$adult; echo "Child".$child; echo "Concession".$conc; Quote Link to comment https://forums.phpfreaks.com/topic/231179-if-statment-inside-a-for-loop/#findComment-1189899 Share on other sites More sharing options...
hyster Posted March 20, 2011 Author Share Posted March 20, 2011 big thanks m8. i knew it was something simple id over looked. Quote Link to comment https://forums.phpfreaks.com/topic/231179-if-statment-inside-a-for-loop/#findComment-1189900 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.