checkbox - Count selected checkboxes by category in form (PHP) -
i have form in website have check things using checkboxes. checkbox names different according how many "points" user gets checking checkbox. clarity names of checkboxes i.e name="this_gives_1" if checkbox gives 1 point. name="this_gives_5"gives obv. 5 points. @ end sum points using:
$points_in_total= 0; $question_one_point = $_post['this_gives_1']; $question_one_point_count = count($question_one_point); $points_in_total = $points_in_total + $question_one_point_count; $question_two_point = $_post['this_gives_2']; $question_two_point_count = count($question_two_point)*2; $points_in_total = $points_in_total + $question_two_point_count; $question_three_point = $_post['this_gives_3']; $question_three_point_count = count($question_three_point)*3; $points_in_total = $points_in_total + $question_three_point_count; $question_five_point = $_post['this_gives_5']; $question_five_point_count = count($question_five_point)*5; $points_in_total = $points_in_total + $question_five_point_count; $question_eight_point = $_post['this_gives_8']; $question_eight_point_count = count($question_eight_point)*8; $points_in_total = ceil(($points_in_total); $email_message .= "you got ".$points_in_total"; now want here is, want add system checks things , using simple boolean tells, if user or not.
for example if there checkboxes "porche", "ferrari", "fiat" , user checks 1 of them, system think: number of checked checkboxes in category "cars" > 0, user likes cars. , if number example 0, says: "i think dont cars".
so can use id anwsers related cars doing:
<input id="car" name="this_gives_5[]" type="checkbox" value="ferrari">ferrari <input id="car" name="this_gives_1[]" type="checkbox" value="fiat">ferrari <input id="fruit" name="this_gives_1[]" type="checkbox" value="banana">banana <input id="fruit" name="this_gives_3[]" type="checkbox" value="apple">apple <input id="fruit" name="this_gives_5[]" type="checkbox" value="tomato">tomato and using id's count, how many "cars" checked (or fruits ect.)?
if ($points_in_total_of_id_cars > 2) { $email_message .= "you cars!"; } elseif ($lukumaara > 0) { $email_message .= "you cars"; } else { $email_message .= "you dont cars, because didn't check one"; } so once again, how i
1) build so, can count 1 spesific category of items; 2) create simple if-elseif give user feedback of in example above?
Comments
Post a Comment