Jump to content


Photo

**solved** n00b problem: looping?


  • Please log in to reply
2 replies to this topic

#1 Cely

Cely
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 03 June 2006 - 07:13 PM

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.

       |1pt |2pts|3pts|4pts|5pts|
icon 1 | x  |    |  x |  x |    |
icon 2 |    |  x |    |    |  x |
icon 3 | x  |    |  x |    |    |
icon 4 |    |  x |    |    |  x |
icon 5 |    |    |    |    |    |


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

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,164 posts

Posted 03 June 2006 - 11:16 PM

try

<?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>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 Cely

Cely
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 03 June 2006 - 11:29 PM

Oh! That works perfectly :D Thank you ^^




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users