SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    574
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help with sort()

    I have 3 workshop choices as select boxes on a form -- like Workshop A, Workshop B, Workshop C. The drop down box for each workshop has 3 options: "First choice", "Second choice", "Third choice". The user is supposed to rank order his/her preference for workshops. I'm trying to figure out how to take the input and then output a string that says something like:

    Your first choice is: Workshop C
    Your second choice is: Workshop A
    Your third choice is: Workshop B

    I know that I need to collect the values in an array and then use sort(), but I can't wrap my mind around how to do it. Here's how I have each select box coded right now, but if there's a better way, that's cool. I have a hunch I'm missing a conceptual piece so I may need to start from scratch:

    PHP Code:
    <select name="saWorkshopID">
    <
    option value="' . $_SESSION["saWorkshopID"] . '">';

        if ($_SESSION["saWorkshopID"] == 1){
            $saForm .= "1st Choice";
        } else if ($_SESSION["saWorkshopID"] == 2){
            $saForm .= "2nd Choice";
        } else if ($_SESSION["saWorkshopID"] == 3){
            $saForm .= "3rd Choice";
        }
        
    $saForm .= '
    <option value="1">1st Choice
    <option value="2">2nd Choice
    <option value="3">3rd Choice
    </selectWorkshop A 

  2. #2
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Wouldn't it be much easier for you to have 3 selects this way
    Code:
    <select name="first_choise">
    <option value="Workshop A">Workshop A</option>
    <option value="Workshop B">Workshop B</option>
    <option value="Workshop C">Workshop C</option>
    </select>
    <select name="second_choise">
    <option value="Workshop A">Workshop A</option>
    <option value="Workshop B">Workshop B</option>
    <option value="Workshop C">Workshop C</option>
    </select>
    <select name="third_choise">
    <option value="Workshop A">Workshop A</option>
    <option value="Workshop B">Workshop B</option>
    <option value="Workshop C">Workshop C</option>
    </select>
    You will get what you want without a need to sort things out.
    -- Jelena --

  3. #3
    SitePoint Evangelist
    Join Date
    Aug 2005
    Posts
    574
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Holy moly. I honestly hadn't even thought of that. I'll have to run that change by the designer, who'll probably have to check with her boss. The site is for people with disabilities, so sometimes they've done things a certain way for reasons that are beyond me. They may still tell me I have to do it the original way but your idea sure seems more intuitive to me.

  4. #4
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The only problem with both ways is that you have to ensure, I believe, that user doesn't select the same Workgroup for more then one choise, or the same choise for more then one Workgroup. Let me know which way you've decided to go with.
    -- Jelena --


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
  •