Cely Posted June 3, 2006 Share Posted June 3, 2006 Hi [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /] I'm trying to create a script to tally up voting-by-checkbox for several different icons, but I'm not sure how to set it up so that one loop adds each *seperately*. Or would I have to write a snippet for each? There are 50 icons per batch, so I really hope it's the former.[code] |1pt |2pts|3pts|4pts|5pts|icon 1 | x | | x | x | |icon 2 | | x | | | x |icon 3 | x | | x | | |icon 4 | | x | | | x |icon 5 | | | | | |[/code]icon 1 = 8ptsicon 2 = 7ptsetc...Hope I've explained everything alright [img src=\"style_emoticons/[#EMO_DIR#]/unsure.gif\" style=\"vertical-align:middle\" emoid=\":unsure:\" border=\"0\" alt=\"unsure.gif\" /] Link to comment https://forums.phpfreaks.com/topic/11108-solved-n00b-problem-looping/ Share on other sites More sharing options...
Barand Posted June 3, 2006 Share Posted June 3, 2006 try[code]<?php if (isset($_GET['pts'])) { foreach($_GET['pts'] as $icon => $scores) { $score = array_sum($scores); echo "Icon $icon = $score pts<br/>"; } }?><FORM><table> <tr> <td> ICON </td> <td> 1pt </td> <td> 2pts </td> <td> 3pts </td> <td> 4pts </td> <td> 5pts </td> </tr> <tr> <td> Icon 1 </td> <td> <input type="checkbox" name="pts[1][]" value="1"> </td> <td> <input type="checkbox" name="pts[1][]" value="2"> </td> <td> <input type="checkbox" name="pts[1][]" value="3"> </td> <td> <input type="checkbox" name="pts[1][]" value="4"> </td> <td> <input type="checkbox" name="pts[1][]" value="5"> </td> </tr> <tr> <td> Icon 2 </td> <td> <input type="checkbox" name="pts[2][]" value="1"> </td> <td> <input type="checkbox" name="pts[2][]" value="2"> </td> <td> <input type="checkbox" name="pts[2][]" value="3"> </td> <td> <input type="checkbox" name="pts[2][]" value="4"> </td> <td> <input type="checkbox" name="pts[2][]" value="5"> </td> </tr></table><input type="submit" name="submit" value="Submit"></FORM>[/code] Link to comment https://forums.phpfreaks.com/topic/11108-solved-n00b-problem-looping/#findComment-41591 Share on other sites More sharing options...
Cely Posted June 3, 2006 Author Share Posted June 3, 2006 Oh! That works perfectly :D Thank you ^^ Link to comment https://forums.phpfreaks.com/topic/11108-solved-n00b-problem-looping/#findComment-41594 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.