At 4:55 PM +0100 8/27/08, JOHN DILLON wrote:
Perhaps this example may help. Eg: a form with checkboxes and submit button, a few are checked and I want to delete the corresponding records from the database. The database table has an ID column:

for each ($argv as $key=>$value) {
   //$key is named cb_1 $value is "checked"
   //to get 1 from the key name, then
   //needed: function like nameof()
   $var=nameof($key);
   $ID=substr($var,3);
   $query="delete * from dbtable where ID='$ID'";
   //etc
}


Okay, your data is coming in from a form and you want to translate that data to a php array -- here's how to do it:

In your form you use:

<input type="checkbox" name="a1">
<input type="hidden" name="whatever1" value="103">

<input type="checkbox" name="a2">
<input type="hidden" name="whatever2" value="206">

<input type="checkbox" name="a3">
<input type="hidden" name="whatever3" value="1187">

<input type="checkbox" name="a4">
<input type="hidden" name="whatever4" value="6101">

In your receiving php script, you use:

for ($i = 1; $i <= 4; $i++)
   {
   $a = 'a' . $i;
   $b = 'whatever' . $i;
   if($_POST[$a] == 'on')
      {
       my_array[] = $_POST[$b]
      }
   }

If a user clicks any/all of the checkboxes, then those checkboxes will be turned 'on' and the values associated with the hidden fields will come into play and be recorded in the my_array[].

A "count(my_array)" will provide you with the number of checkboxes that were actually checked.

Sure you can do this in while statements if you wish, but the idea of how to translate checkboxes to a php array is here.

The hidden values above could just as easily be values taken from a database corresponding to record deletions, such as:

<input type="hidden" name="whatever4" value="<?php echo($record_ID");?>">

The point is that you can determine what the user clicked and tied it to whatever you presented.

Cheers,

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to