better way to create custom text file from query results?

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

Attachment: [application/pkcs7-signature] smime.p7s
« previous php.general (#237553) next »