Re: Re: Variable name as a string

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In writing the script, though, there are two points. I don't always use checkboxes, sometimes I just want to update all the records on the form. Eg I have a series of images and related text each with their ID in the database table, on clicking update all the form elements get submitted and I need to relate the relevant image, text, etc with the table ID. So I can't rely on checkboxes which only get posted if ticked. So again I have to iterate through all possible IDs. Which normally can be done but it is longer, eg because the images on the page in the first place may not be the result of a simple select query. So I suppose the solution there is to have a hidden field with all the IDs as a string, explode that and then iterate through that. Eg

<input type=hidden value="1_2_3" name="all_IDs">

$IDs=explode("_",$_POST['all_IDs']);

and that gives me the table IDs to do update queries on etc.

John

ioannes wrote:
Actually, you are right, as you just put the checkbox index in the POST and get the value from there. So you just need the number of checkboxes...sorry.

ioannes wrote:
Yes, Tedd, this does however incur the overhead of find out what i is, because it could be a range of IDs from the database, not necessarily a count of the checkboxes on the page:

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

John



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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux