In article <000201c24ec3$d884db50$8102a8c0@000347D72515>, 
> So these 4 variables walk into a bar.... :^]
> I have a form with 4 drop downs. Each of these drop downs might have a value
> and there is no order in which they might have a value. A query needs to
> built (the WHERE and AND portions) that takes into account which ever
> variables have been set. A user may choose a variable that would not be in
> the first location.
> $var1 = is not set
> $var2 = is set
> $var3 = is set
> $var4 = is not set
> (or any other combination) The query, of course, needs to be in order taking
> into account the above example;
> $query = "SELECT foo ";
> $query .= "FROM bar ";
> $query .= "WHERE thus = '" . $var2 . "' ";
> $query .= "AND thus = '" . $var3 . "' ";
> If three of the variables are set then there would need to be an additional
> AND statement, etc. It would be foolhardy to construct an if or case
> statement that would take into account each possible combination. I have
> been thinking this through for an hour or so, but I am not seeing a clear,
> elegant, and efficient piece of code. Has anyone done anything like this, or
> does anyone have an idea of how this might be done?
> TIA!
> Jay

One possibility:
make an array of the $varn that are set
count the array elements
if 0 elemet - error handling
build basic query 
// $query = "Select foo from bar WHERE x = $element[0]"
if >1 element, add additional AND by looping through balance of array

Code is left as an exercise for the student :-)

David Robley
Temporary Kiwi!

Quod subigo farinam

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to