Hi Bryan:
I've created something similar and if I understand your question correctly then you would want to do something like this. What this code snippet does is as follows:
It takes an array of HTML checkboxs named webops and checks to see if it has been checked, if it has then it adds it to the INSERT statement that I do at the end of the line, if not it skips it and moves on to the next one. Once it ends the for loop (exhausts all available checkboxes) the array terminates and I parse out the string that it builds into a SELECT statement that I use to select a record from a database based on the users' options.
// arr is the array that holds the user selections for output display
// count the number of items selected
$count=count($arr);
// check to see if there is a value for category select list drop down
if ($category != "") {
if ($categoryValue != "") {
$qualifier = " WHERE $category='$categoryValue'";
}
}
else {
$qualifier = "";
}
// since the sql query can select additional information to be viewed, the
// checkbox is used to include additional selections in the sql query
for ($i=0; $i<$count; $i++) {
$str = $arr[$i];
switch ($str) {
case "name" : $temp[$i] = ",name"; break;
case "phone" : $temp[$i] = ",phone"; break;
case "cell" : $temp[$i] = ",cell"; break;
case "pager" : $temp[$i] = ",pager"; break;
default : $temp[$i] = ""; $temp[$i] = "";
}
}
// put the user display preferrences in a temporary array that will be used
// to write the select statement for the database.
for ($i=0; $i<(count($temp)-1); $i++) {
$parts="$parts$temp[$i]";
}
// for the last item, remove the comma
$gimbo="$temp[$i]";
$parts="$parts$gimbo";
$headerList="logonID,lName,fName$parts";
$hdrArray = explode(",", $headerList);
// write the select statement, the $default variable holds the generic search string
$sql = "SELECT id,$parts FROM tableName$qualifier";
So if a user goes into my form and checks I want to view the record for <checkbox1><checkbox2><checkbox4>
This parses out the request and builds a string based on those checkboxes that were checked and writes out the following $sql statement:
"SELECT id,$checkbox1,$checkbox2,$checkbox4 FROM table WHERE $qualifier";
Hope that helps. Enjoy!
jm _
Contact Shuba Gooba Designs
for Web Programming
janmichaelong@netscape.net