Yes, this is in the PHP FAQ.

Plus, you could name them like:
name="fieldname[1]" and then you could just iterate through
$_POST['fieldname'] which would be even cleaner.


On Wed, June 7, 2006 7:21 am, Ben Liu wrote:
> Hello All,
>
> I've written a clunky script that presents a form to a user with 30
> checkboxes on it to match 30 fields in a table. The user checks off
> each field they want to appear in a text file produced by the script.
> The script I wrote captures each checkbox response to a separate
> variable:
>
> $fieldname1=$_POST['fieldname1'];
> $fieldname2=$_POST['fieldname2'];
>
> etc...
>
> I then build a custom query based on those variables using 30 logic
> statements like such:
>
> if ($fieldname1) $query .="fieldname1, ";
> if ($fieldname2) $query .="fieldname2, ";
>
> etc...
>
> I then query the DB and iterate over the results, shoving the data
> into an output variable like this (again 30 logic statements):
>
> if ($fieldname1) $output.="$row[fieldname1]\t";
> if ($fieldname2) $output.="$row[fieldname2]\t";
>
> then I print the contents of $output to a text file.
>
> It seems that there has to be a better way of doing this. Can the
> $_POST superglobal be manipulated in this way:
>
> foreach ($_POST as $fieldname) ?
>
> Thanks for any help and guidance.
>
> - Ben


-- 
Like Music?
http://l-i-e.com/artists.htm

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

Reply via email to