|
The complexity depends on whether the different boxes access different tables. If they access the same table a good way to tackle this is to load the values into an associative array and then read the array. So an example from a piece of my code that does more or less the same thing would be:
if (!empty($LNAME)) { $textb["LNAME"] = "$LNAME"; }
if (!empty($FNAME)) { $textb["FNAME"] = "$FNAME"; }
if (!empty($ONAME)) { $textb["ONAME"] = "$ONAME"; }
if (!empty($PSEUD)) { $textb["PSEUD"] = "$PSEUD"; }
}
Obviously you would substitute the !empty for '!='. Just make sure the key in the array is the same as the field in the table. This will give you an array with only the set values. Then read the array and build an SQL query like
$CNT = 0;
foreach ($textb as $key => $val) {
$KVAL = "$key = '$val'" ;
if ($CNT == 0 {$CSTAT = "where $KVAL" ;
$CNT++ ;}
else {$CSTAT = "$CSTAT and $KVAL" ;}
}
This builds a conditional statement where on the first iteration you get the where statement and each additional array element gives an 'and' statement. If the select statement depends on the values submitted, it can be built in the same way. If the boxes reference joined tables it becomes more complex, but it can be done by seperating the arrays into one per table that is joined. Also it is fairly easy to substitute other conditions such as != or 'like' if required. Hope this is clear enough.
Bob
|