Jump to content

Archived

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

Cely

**solved** n00b problem: looping?

Recommended Posts

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 = 8pts
icon 2 = 7pts

etc...

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\" /]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

×

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.