skartdo Posted June 22, 2008 Share Posted June 22, 2008 I want to add together the values of a series of check boxes then multiply the result by a number that is derived from adding together the values of another different series of check boxes. Any thoughts? thanks Link to comment https://forums.phpfreaks.com/topic/111331-add-and-multiply-results-of-a-form/ Share on other sites More sharing options...
Barand Posted June 22, 2008 Share Posted June 22, 2008 Group the c/boxes on the form into two arrays. When posted then you can use array_sum() on each group The first group all have same name, say, name='gp1[]' and second set have name='gp2[]'. to process $tot1 = array_sum($_POST['gp1']; $tot2 = array_sum($_POST['gp2']; edit by ober to add closing php tags. Link to comment https://forums.phpfreaks.com/topic/111331-add-and-multiply-results-of-a-form/#findComment-571653 Share on other sites More sharing options...
alco19357 Posted July 9, 2008 Share Posted July 9, 2008 HTML FORM <form action="" method="post"> 1<br> <input type="checkbox" value="3" name="cb1[]"><br> <input type="checkbox" value="6" name="cb1[]"><br> <input type="checkbox" value="8" name="cb1[]"><br><br> 2<br> <input type="checkbox" value="1" name="cb2[]"><br> <input type="checkbox" value="2" name="cb2[]"><br> <input type="checkbox" value="3" name="cb2[]"><br> <input type="submit" value="calculate"> </form> php $group1 = $_POST['cb1']; $group2 = $_POST['cb2']; //calculate group 1 $group1_value = 0; for($i=0; $i<count($group1); $i++){ $group1_value = ($group1[$i])+($group1_value); } //calculate group 2 $group2_value = 0; for($q=0; $q<count($group2); $q++){ $group2_value = ($group2[$q])+($group2_value); } //multiply group 1 and 2 $end_value = $group1_value*$group2_value; echo "End Value = ".$end_value; How bout something like that? Link to comment https://forums.phpfreaks.com/topic/111331-add-and-multiply-results-of-a-form/#findComment-585616 Share on other sites More sharing options...
Barand Posted July 9, 2008 Share Posted July 9, 2008 or $end_value = array_sum($_POST['gp1']) * array_sum($_POST['gp2']) ; Link to comment https://forums.phpfreaks.com/topic/111331-add-and-multiply-results-of-a-form/#findComment-585681 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.