Creating a dropdown menu filter?
I'm not sure of the correct terminology, but here is what I'm looking to develop:
Like monster.com or any of the major job search companies, I'd like to create a database connected to an online form, with two dropdown menus, which will provide filtered search results upon submit.
First dropdown menu: Arizona, Alaska, Alabama
Second menu: Carpenters, Plumbers, Auto Repair
If the user were to select Arizona, Carpenters and click submit, the next page would be a listing of all the Carpenters in AZ.
I believe I'll have to incorporate PHP/MySQL, but I'd like any advice or resources that might be available.
Yes, you got it right. You can use PHP and MySQL to do that. I suggest you learn some basic SQL select statements. Then use PHP to pass post/get to next page for processing the sql select statement. A little pseudo-code here, assuming you know a little about HTML in the first place!
// THIS IS IN THE SELECTION PAGE
<form action="showJobs.php" method="post">
<option value="" selected="selected">Choose a state</option>
<option value="" selected="selected">Choose a job</option>
<input type="submit" value="search jobs" />
Consult the PHP manual at php.net and search for MySQL.
// THIS IS IN THE FILTERED PAGE
$dState = $_POST["cboLocation"];
$dJob = $_POST["cboJob"];
$sqlQuery = "SELECT * FROM tblJobs WHERE state=\"$dState\" AND job=\"$dJob\"";
//RUN THE QUERY
Hope this is a good start for you.
Just wanted to say thanks for the code help, this was giving me problems too, your advice was very simple and to the point. Thanks.
I'm doing something a little similar, and can't for the life of my figure out how to do the following (I'm also brand new to php and mysql):
Let's say, using the OP's example, that I have the two menus (one with Arizona, Alaska, and Alabama, and one with Carpenters, Plumbers, and Auto Repair).
However, instead of requiring both a 'state' and a 'job,' the user has the option of selecting just one or the other, so that if the user selects "Arizona" and leaves the 'jobs' menu as is (for example, at the default option of '-----' or 'Jobs'), we would be returned all of the carpenters, plumbers, and auto mechanics in Arizona. Or if the state was left at the default, and 'carpenters' was selected, then all the carpenters in Arizona, Alaska, and Alabama would be returned.
What would be a good way to code this?
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)