SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Feb 2011
    Location
    Colorado, USA
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    best way for user to sort results

    I am making a site so users can track their golf game.

    I currently use this query to display all data. In the courses table.
    PHP Code:
    <?php
                $result 
    mysql_query("SELECT * FROM courses ORDER BY coursename ASC");
                while (
    $row=mysql_fetch_array($result)) {
                echo 
    "<a href='course.php?C=".$row['id']."'>".$row['courseName']."<a/><br />";}
                        
                        
    ?>
    The table has 16 columns, the only columns I want to work with is state then city.
    I want to make it so that a user selects a state from a dropdown list, after selecting the state I want another dropdown list with the cities of that state, after selecting the city I want to display all the "courseName"'s that fall under that city and state. I also want to make a option to choose all cities in the state. I have been working on a way to do this with 3 different pages but I would like to make if all on one page. Any help is appreciated.

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    The traditional and less user-friendly way is to put up a form with just the states, when submitted a second page displays all the cities in that state and finally a third page displays all the golf courses.

    I want to make it so that a user selects a state from a dropdown list, after selecting the state I want another dropdown list with the cities of that state,
    That is often termed a "linked drop list" or "linked select boxes" or "linked drop down menu php"

    Searching for those terms will turn up a way of achieving this on the client. Essentially, PHP creates the full array of states and cities, turns them into JS arrays and sends the lot to the client - heavy, but once loaded the sorting is instantaneous.

    Another way to do this is to use Ajax to refresh parts of the page.

    Which you choose may depend on;

    a) your skills
    b) whether you want your site to work with JS turned off
    c) how many states/cities/golf courses you have

    I presume this is what you were asking about rather than how to build up the sql statements ...


Bookmarks

Posting Permissions

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