At 8:21 AM -0400 6/7/06, 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. Ben: What you did doesn't look bad to me. If you understand it, it's obvious, and it works... But, if it was my code, I might take steps one and two and combine them, and run the process through a loop, like so: for ($i = 1; $<=30; $I) { if ($_POST['$i']) $query .="$i, "; } And then assemble the data the same way. for ($i = 1; $<=30; $I) { if ($i) $output.="$row[$i]\t"; } This is written on the fly, so it may not work as I expect, but I'm sure you get the idea. hth's tedd -- ------------------------------------------------------------------------------------ http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php