create multiple drop down menus to filter mysql query?
Hello all,
I've been using webdeveloper.com for a while now but I never needed to ask my own question since I usually found it in search, but this time its different
Here is my problem,
I am currently building a page that uses five separate drop down menus (static content) that when selected the combination of what is selected will filter my mysql query and display the correct results using those parameters.
I have everything set up to work when one or another variable is sent, however I am having trouble creating a way to set up the query string where non of the filter options are required.
and here is my php code that deals with the query, it is far from finished, not even using all the options in the drop down. I started trying to build a big if/elseif tree but that isn't working out. I am also using the smarty and pear libraries, so I apologize if it looks non-standard.
what I need help with is a way to craft the filtering string so that the options are not required, a catch all way to select any combination of filters and for the query to work.
Any help would be appreciated, and Thank you very much for your time.
This thread and post number four explain it a little better than I did. I am trying to write the tree so that any combination of selections in the drop down will result in a successful query. ie. state only or state, size and activity, or radius and activity.
is that any better?
Originally Posted by bokeh
I don't really know what you are trying to do, the question isn't too clear. Maybe something like this:
That will always be true. You are setting a variable, not checking for equality.
AHH! I feel silly, thank you! that did fix the tree for all the single drop down selections. Like, if someone only picks state or radius and leaves the rest alone. But what about the multiple selections?
I was able to get it all to work with some tweaking and the direction you pointed me in. Thank you very much for all your help. Might be a little overkill but it works haha just have to work on optimizing my code.
Hello, sorry to reply for and old thread. But I been google around and this is the same thing that i needed help with. I have 2 drop down menu and a submit button. I try to us nickpalmigiano's if condition to filter result, but where do I apply the $filter and $order variables on the Mysql_query. Does this code look right...
$sql = mysql_query("SELECT * FROM mytable WHERE Category='".$filter."' && SubCat='".$filter."' ORDER BY $order");
--below is my 2 drop down menu populated using javascript--
<FORM name="drop_list" action="joboutput2.php" method="POST" >
<label>
<SELECT NAME="Category" size="1" id="Category" onChange="SelectSubCat();" >
<Option value="All">所有</option>
</SELECT>
<SELECT NAME="SubCat" id="SubCat" >
<Option value="All">所有</option>
</SELECT>
<input type="Submit" name="Form3" value="搜索"/>
</label>
</form></div>
you can't use same variable for both category and sub-category as i think, both will be having different values..in this case, you just need to use following code:
$category=$_POST['Category'];
$subcategory=$_POST['SubCat'];
$sql = mysql_query("SELECT * FROM mytable WHERE Category='$category' and SubCat='$subcategory' ");
hi there. I created HTML and PHP file to filter web form data based on multiple drop down filters. Here goes the form. when i run the form and PHP, i don't see any results in the browser. There is no error either. I am working on a example posted by another forum member.Pls. help. Thanks in advance.
Bookmarks