better way to create custom text file from query results?

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

 



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: smime.p7s
Description: S/MIME cryptographic signature


[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