vendredi 5 mai 2017

Getting count of Checkbox array in php, displaying specific value in textbox

is there a way i can get the count of an array of checkboxes, say there are like 4 arrays(yeswb[], yesab[], yesal[], yesvb[]). In need to get the count of the arrays yeswb[], yesab[], yesal[] and yesvb[], compare the largest count amongst them and display a specific value on a textfield.

<form action="checkbox.php" method="POST">
                        <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                    <thead>
                                        <tr>
                                        <th>Indicator/Symptom</th>
                                            <th>Yes</th>
                                            <th>No</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr class="gradeA"> 
                                        <td>Headache</td>
                                        <td><input type="checkbox" name="yeswb[]" value="Headache"></td>
                                        <td><input type="checkbox" name="nowb[]" value="No Headache"></td>
                                    </tr>
                                    <tr class="gradeA">
                                        <td>Diarrhoea</td>
                                        <td><input type="checkbox" name="yeswb[]" value="Yes"></td>
                                        <td><input type="checkbox" name="nowb[]" value="No"></td>
                                    </tr>
                                    <tr class="gradeA">
                                        <td>Vomiting</td>
                                        <td><input type="checkbox" name="yeswb[]" value="Yes"></td>
                                        <td><input type="checkbox" name="nowb[]" value="No"></td>
                                    </tr>
                                    <tr class="gradeA">
                                        <td>Constipation</td>
                                        <td><input type="checkbox" name="yeswb[]" value="Yes"></td>
                                        <td><input type="checkbox" name="nowb[]" value="No"></td>
                                    </tr>
                                    <tr class="gradeA">
                                        <td>Nausea</td>
                                        <td><input type="checkbox" name="yeswb[]" value="Yes"></td>
                                        <td><input type="checkbox" name="nowb[]" value="No"></td>
                                    </tr>
                                    <tr class="gradeA">
                                        <td>No Appetite</td>
                                        <td><input type="checkbox" name="yeswb[]" value="Yes"></td>
                                        <td><input type="checkbox" name="nowb[]" value="No"></td>

                                    </tr>
                                    <tr class="gradeA">
                                        <td>Sneezing</td>
                                        <td><input type="checkbox" name="yesab[]" value="Yes"></td>
                                        <td><input type="checkbox" name="noab[]" value="No"></td>
                                    </tr>
                                    <tr class="gradeA">
                                        <td>Runny Nose</td>
                                        <td><input type="checkbox" name="yesab[]" value="Yes"></td>
                                        <td><input type="checkbox" name="noab[]" value="No"></td>
                                    </tr>
                                    <tr class="gradeA">
                                        <td>Coughing</td>
                                        <td><input type="checkbox" name="yesab[]" value="Yes"></td>
                                        <td><input type="checkbox" name="noab[]" value="No"></td>
                                    </tr>
                                    <tr class="gradeA">
                                        <td>Itchy eyes and nose</td>
                                        <td><input type="checkbox" name="yesab[]" value="Yes"></td>
                                        <td><input type="checkbox" name="noab[]" value="No"></td>
                                    </tr>
                                    <tr class="gradeA">
                                        <td> Watery eyes</td>
                                        <td><input type="checkbox" name="yesab[]" value="Yes"></td>
                                        <td><input type="checkbox" name="noab[]" value="No"></td>
                                    </tr>
                                    <tr class="gradeA">
                                        <td>Fatigue</td>
                                        <td><input type="checkbox" name="yesvb[]" value="Yes"></td>
                                        <td><input type="checkbox" name="novb[]" value="No"></td>
                                    </tr>
                                    <tr class="gradeA">
                                        <td>Chills & Fever</td>
                                        <td><input type="checkbox" name="yesvb[]" value="Yes"></td>
                                        <td><input type="checkbox" name="novb[]" value="No"></td>
                                    </tr>
                                    <tr class="gradeA">
                                        <td>Muscle/Joint aches</td>
                                        <td><input type="checkbox" name="yesvb[]" value="Yes"></td>
                                        <td><input type="checkbox" name="novb[]" value="No"></td>
                                    </tr>
                                    <tr class="gradeA">
                                        <td> Swollen Lymph Nodes</td>
                                        <td><input type="checkbox" name="yesvb[]" value="Yes"></td>
                                        <td><input type="checkbox" name="novb[]" value="No"></td>
                                    </tr>
                                    <tr class="gradeA">
                                        <td>Expanding Rash</td>
                                        <td><input type="checkbox" name="yesvb[]" value="Yes"></td>
                                        <td><input type="checkbox" name="novb[]" value="No"></td>
                                    </tr>
                                    <tr class="gradeA">
                                        <td>Redrash</td>
                                        <td><input type="checkbox" name="yesal[]" value="Yes"></td>
                                        <td><input type="checkbox" name="noal[]" value="No"></td>
                                    </tr>

                                    <tr class="gradeA">
                                        <td>Wheezing</td>
                                        <td><input type="checkbox" name="yesal[]" value="Yes"></td>
                                        <td><input type="checkbox" name="noal[]" value="No"></td>

                                    </tr>
                                    <tr class="gradeA">
                                        <td>Swollenness</td>
                                        <td><input type="checkbox" name="yesal[]" value="Yes"></td>
                                        <td><input type="checkbox" name="noal[]" value="No"></td>

                                    </tr>

                                    </tbody>
                                </table> 
                                </form> 

say for example the count of yeswb[] is 4, the count of yesab[] is 3 and the count of yesvb[] is 1, how will I generate a statement like yeswb[] wins in a textfield? (because with a count of 4 yeswb[]is the greatest) thank you in advance.




Aucun commentaire:

Enregistrer un commentaire