Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

ASP Database Query from Dropdown

Options
  • 23-02-2007 12:13pm
    #1
    Registered Users Posts: 782 ✭✭✭


    Hi All,
    I am fairly new to ASP but i am writing a webpage to retrieve details from an MDB file (Access). Now it is simple to get the details back if you want everything with the code from: http://www.codefixer.com/tutorials/form_to_database.asp

    Now this works a treat, especially to input to the database.
    This is probably simple but i would like to make a page with dropdown boxes and use the input from the dropdown box to be the WHERE xxx part...
    So if i choose RED from the dropdown box it would change the SELECT statement to display "Select * from DB where colour like RED(dropdown result)

    Any quick ideas on how this is done please?
    Cheers in advance,
    M


Comments

  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    gibo_ie wrote:
    Hi All,
    I am fairly new to ASP but i am writing a webpage to retrieve details from an MDB file (Access). Now it is simple to get the details back if you want everything with the code from: http://www.codefixer.com/tutorials/form_to_database.asp

    Now this works a treat, especially to input to the database.
    This is probably simple but i would like to make a page with dropdown boxes and use the input from the dropdown box to be the WHERE xxx part...
    So if i choose RED from the dropdown box it would change the SELECT statement to display "Select * from DB where colour like RED(dropdown result)

    Any quick ideas on how this is done please?
    Cheers in advance,
    M

    Your ASP code:
    If Request.ServerVariables("HTTP_METHOD") = "POST" Then ' form has been submitted
        Dim sColour, sSQL
        sColour = Request.Form("lstColour")
        sSQL = "select * from mytable where mycolour = '" & sColour & "'"
        ....etc
    End If
    

    Your dropdown
    [HTML]<select id="lstColour">
    <option value="red">red</option>
    <option value="green">green</option>
    <option value="blue">blue</option>
    </select>[/HTML]

    That what you're looking for?


  • Registered Users Posts: 782 ✭✭✭gibo_ie


    looks like it eoin!
    Wont get a chance to test this till tonight but thanks a mil!!!
    I guess it will be pretty much the same if i need two results, and use the AND paramater?

    Anyway kudos to you! Thanks


  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    gibo_ie wrote:
    looks like it eoin!
    Wont get a chance to test this till tonight but thanks a mil!!!
    I guess it will be pretty much the same if i need two results, and use the AND paramater?

    Anyway kudos to you! Thanks

    No worries!

    Yep, use the AND parameter if you want to build up the sql statement. PM me or post here if you have any problems with that.

    e.g.
    If Request.ServerVariables("HTTP_METHOD") = "POST" Then ' form has been submitted
        Dim sColour, sSQL, sShade
        sColour = Request.Form("lstColour")
        sShade = Request.Form("lstShade")
        sSQL = "select * from mytable where mycolour = '" & sColour & "' AND myshade = '" & sShade & "'"
        ....etc
    End If
    

    [html]
    <select id="lstColour">
    <option value="red">red</option>
    <option value="green">green</option>
    <option value="blue">blue</option>
    </select>

    <select id="lstShade">
    <option value="light">light</option>
    <option value="dark">dark</option>
    </select>
    [/html]


Advertisement