www.webdeveloper.com
Results 1 to 4 of 4

Thread: Creating a dropdown menu filter?

  1. #1
    Join Date
    Feb 2006
    Posts
    2

    Creating a dropdown menu filter?

    Hello!

    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.

    For example:
    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.

    Thank you!

  2. #2
    Join Date
    Feb 2006
    Posts
    6
    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!

    Code:
    // THIS IS IN THE SELECTION PAGE
    <form action="showJobs.php" method="post">
    <select name="cboLocation">
    <option value="" selected="selected">Choose a state</option>
    <option value="arizona">Arizona</option>
    <option value="alaska">Alaska</option>
    </select>
    <select name="cboJob">
    <option value="" selected="selected">Choose a job</option>
    <option value="arizona">Carpenters</option>
    <option value="alaska">Plumbers</option>
    </select>
    <input type="submit" value="search jobs" />
    </form>
    Code:
    // THIS IS IN THE FILTERED PAGE
    <?php
    $dState = $_POST["cboLocation"];
    $dJob = $_POST["cboJob"];
    
    $sqlQuery = "SELECT * FROM tblJobs WHERE state=\"$dState\" AND job=\"$dJob\"";
    
    //RUN THE QUERY
    
    //DISPLAY RESULT
    ?>
    Consult the PHP manual at php.net and search for MySQL.

    Hope this is a good start for you.

    [/code]

  3. #3
    Join Date
    Nov 2008
    Posts
    1
    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.

  4. #4
    Join Date
    Dec 2008
    Posts
    1
    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?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles