Jump to content

[SOLVED] count problam.


redarrow

Recommended Posts

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>

 

Link to comment
https://forums.phpfreaks.com/topic/143065-solved-count-problam/
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/143065-solved-count-problam/#findComment-750310
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.