Re: better way to create custom text file from query results?

From: Date: Mon, 12 Jun 2006 20:59:07 +0000
Subject: Re: better way to create custom text file from query results?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-237846@lists.php.net to get a copy of this message
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

« previous php.general (#237846) next »