That solution would probably work just nicely.

That being said however, If you want to be sophisticated about this you
would make good use of JSON and php's corresponding functions
json_decode/encode which is common way to transport arrays as strings - and
much more.



-----Original Message-----
From: ioannes [mailto:[EMAIL PROTECTED] 
Sent: Friday, 29 August 2008 1:22 PM
To: php-general@lists.php.net
Subject: Re: [PHP] Re: Variable name as a string

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


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

Reply via email to