seahorse123
Programmer
I want to submit a form, which has multiple dropdown menu: dd1, dd2,dd3.
these values will be passed to the process page to populate the data from DB, on the process page I have code:
Now the problem is:
On submit form, user can select one or more dropdown menu, but on process page, how to write the correct WHERE clause? Right now, if user select "dd1", then SELECT statement works fine("select * from table where field1=$v_dd1), but if user only select "dd2", then SELECT statement will be wrong("select * from table where and field2=$v_dd2"), there is an extra "and" in the statement.
anyone can help me? thanks
michael
these values will be passed to the process page to populate the data from DB, on the process page I have code:
Code:
$v_dd1=$_request['dd1'];
$v_dd2=$_request['dd2'];
$v_dd3=$_request['dd3'];
if(($v_dd1)<>'') {$clause = "field1=$v_dd1";}
if(($v_dd2)<>'') {$clause .= "and field2=$v_dd2";}
if(($v_dd3)<>'') {$clause .= "and field3=$v_dd3";}
select * from table where $clause;
Now the problem is:
On submit form, user can select one or more dropdown menu, but on process page, how to write the correct WHERE clause? Right now, if user select "dd1", then SELECT statement works fine("select * from table where field1=$v_dd1), but if user only select "dd2", then SELECT statement will be wrong("select * from table where and field2=$v_dd2"), there is an extra "and" in the statement.
anyone can help me? thanks
michael