Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts

    How to pass variable to PHP query

    I am using a <select> with multiple options that a user will select one from. Each option has a value assigned. Once the user has made their selection, I am wanting to pass the value of the option they selected to use as part of a database query that will give the user additional options based on the option they selected.
    Something like this:
    <select>
    <option value=1>option1</option>
    <option value=2>option2</option>
    <option value=3>option3</option>
    etc...
    </select>

    User makes their selection...say option2, for example.

    Then value of option selected is used in database query like:
    <select * from table where var=2>
    From here I generate additional field with more options, depending on what option the user selects from the first field.

    I have read this can be done by adding a bit a javascript and then reloading/redirecting to another page. I am wanting to do this while staying on the same page. Reloading/redirecting will clear the fields the user has already completed. Can this be done on the same page?

    I just want the user to make a selection from one field and then provide additional fields that are connected to the selection they made. I have seen this done plenty of times on various websites...now I want to get it straight on how to make it work.

    (Please forgive my wordiness/rambling...just wanted to be clear on what I was attempting to do)

    Thanks in advance!!!!

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    nanthony (06-20-2012)

  • #3
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    723
    Thanks
    20
    Thanked 84 Times in 84 Posts
    I use something similar but using ajax

    http://www.w3schools.com/php/php_ajax_database.asp

  • Users who have thanked Arcticwarrio for this post:

    nanthony (06-20-2012)

  • #4
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    2
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks to you both for the suggestions!!!!...But I hit a snag, I am trying to do this within Drupal. I was attempting to create a custom template to allow the user to select one field, then adjust the next field based on their selection from the first. Just realized that Drupal does not like me trying to customize the template this way and is not saving the selections made. Have to see if I can manipulate the template to get it to work or scrap this a look for another way....while I have a little hair left.
    Thanks again for the assistance...now I need a Drupal expert!!


  •  

    Posting Permissions

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