redarrow Posted January 30, 2009 Share Posted January 30, 2009 what have i done wrong to count the selected yes or no's cheers. <?php if($_POST['submit']){ $Are_you_a_php_programmer=$_POST['Are_you_a_php_programmer']; $Do_you_no_css=$_POST['Do_you_no_css']; $Do_you_no_html=$_POST['Do_you_no_html']; $Are_you_a_php_programmer=array($testing); $Do_you_no_css=array($testing); $Do_you_no_html=array($testing); for($i=0; $i<count($testing); $i++){ $counted_yes=count('yes',$testing[$i]); $counted_no=count('no',$testing[$i]); } echo "<br><br>Members that said yes are:\n $counted_yes <br> Members that said no:\n $counted_no<br><br>"; } ?> <?php $message=array("Are you a php programmer?","Do you no css","Do you no html"); $name=array("Are_you_a_php_programmer","Do_you_no_css","Do_you_no_html"); ?> <form method="POST" action=""> <?php for($i=0; $i<3; $message++ ,$name,$i++){?> <?php echo $message[$i];?> <br><br> <input type="checkbox" name="<?php echo $name[$i]; ?>" value="yes">YES <input type="checkbox" name="<?php echo $name[$i];?>" value="no">NO <br><br> <?php }?> <br><br> <input type="submit" name="submit" value="SEND!"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/143065-solved-count-problam/ Share on other sites More sharing options...
gevans Posted January 30, 2009 Share Posted January 30, 2009 How about this; <?php $message=array("Are you a php programmer?","Do you no css","Do you no html"); $name=array("Are_you_a_php_programmer","Do_you_no_css","Do_you_no_html"); if($_POST['submit']){ foreach($name as $value) { if($_POST[$value] == 'yes') $counted_yes++; elseif($_POST[$value] == 'no') $counted_no++; } echo "<br><br>Members that said yes are:\n $counted_yes <br> Members that said no:\n $counted_no<br><br>"; } ?> <form method="POST" action=""> <?php for($i=0; $i<3; $message++ ,$name,$i++){?> <?php echo $message[$i];?> <br><br> <input type="checkbox" name="<?php echo $name[$i]; ?>" value="yes">YES <input type="checkbox" name="<?php echo $name[$i];?>" value="no">NO <br><br> <?php }?> <br><br> <input type="submit" name="submit" value="SEND!"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/143065-solved-count-problam/#findComment-750310 Share on other sites More sharing options...
redarrow Posted January 30, 2009 Author Share Posted January 30, 2009 is this what i got wrong i am mind smacked now lol. foreach($name as $value) { if($_POST[$value] == 'yes') $counted_yes++; elseif($_POST[$value] == 'no') $counted_no++; } Quote Link to comment https://forums.phpfreaks.com/topic/143065-solved-count-problam/#findComment-750320 Share on other sites More sharing options...
corbin Posted January 30, 2009 Share Posted January 30, 2009 do print_r($_POST) and look at the output. Quote Link to comment https://forums.phpfreaks.com/topic/143065-solved-count-problam/#findComment-750323 Share on other sites More sharing options...
redarrow Posted January 30, 2009 Author Share Posted January 30, 2009 well i dont no what i was doing cheers solved going mad. Quote Link to comment https://forums.phpfreaks.com/topic/143065-solved-count-problam/#findComment-750332 Share on other sites More sharing options...
akitchin Posted January 30, 2009 Share Posted January 30, 2009 well i dont no what i was doing cheers solved going mad. we also are going mad, because none of these posts made sense.. regardless, congratulations for solving it? Quote Link to comment https://forums.phpfreaks.com/topic/143065-solved-count-problam/#findComment-750933 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.