Using Form Results to fill out form using SQL

Discussion in 'PHP' started by KangBroke, May 28, 2012.

  1. #1
    I have a form.

    Pick your favorite,
    1. Fruit
    2. Veg

    Both are in the same db. But different tables.

    On the same page, below that form there is an empty drop down box.

    Lets say the choose Fruit. It should populate the dropdown box below, using the contents of the `fruit` table, If they choose Veg it will populate the below drop downbox with the contents of the `veg` table.
     
    Solved! View solution.
    KangBroke, May 28, 2012 IP
  2. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #2
    You can't figure that out?

    Use AJAX to send the request.

    Use a SELECT statement to fetch all rows from the specified table.

    Were you looking for someone to do it for you?
     
    NetStar, May 28, 2012 IP
  3. KangBroke

    KangBroke Notable Member

    Messages:
    1,026
    Likes Received:
    59
    Best Answers:
    4
    Trophy Points:
    265
    #3
    Well I could probably figure out the example I wrote above, However its 5:30am. I've been debugging this script for 3 days, And Honestly I may hire someone if it were real cheap, But im sure someone could just point my sleepless mind in the right path.

    The real problem is the db is called x.

    in db x there are groups
    groups get a table

    there are teams
    teams get a table

    So what I have is a registration form. And in that form the 1st field is a preset dropdown. I used SQL to populate this dropdown using the Groups. GroupA, GroupB
    Below is a 2nd dropdown. for Teams. I also have this preset to show the Teams from the teams table.

    All that works fine.

    I just cant seem to remember how to take the results from dropdown one. and make it use that to pull the SQL Query for the 2nd one without the user hitting submit.
     
    KangBroke, May 28, 2012 IP
  4. #4
    Honestly this isn't that hard. And I don't believe you've done your home work. I believe you are lazy and looking for someone to do it for you.

    - Use onSelectChange="blah();" to trigger the JavaScript function blah() when someone changed an item in the first drop down.

    - In blah() use direct AJAX or a JQUERY routine to send the value of the selected item to a PHP script.

    - In the PHP script determine which table to use based on the value of the selected item sent via GET or POST. Execute an SQL statement retrieving all rows in that table.

    - Back in blah() we receive the response then populate the 2nd drop down menu using JavaScript.
     
    NetStar, May 28, 2012 IP
    KangBroke likes this.