#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0

    Unhappy ::Drop down Box value to SQL::


    Hi Guys...

    I got this dropdown box and whet I need to do is when I select the value from dropbox , it has to go to sql statement and show the data accordingly.

    You guys can help me to show how to pass the value from dropbox to same page php variable i.e. $x


    PHP Code:
    <strong>File View : </strong>
            
          <
    select id="pid" name="pid" >

      <
    option value="0">Select</option>
      <
    option value="1">All</option>
      <
    option value="2">Private</option>
      <
    option value="3">Team</option>

    </
    select

    "Query = SELECT * FROM documents WHERE PermissionID=$x"
    This $x should be dropdown list value i.e. 1,2 or 3

    Tx guys.. your help much appreciated !!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,600
    Rep Power
    595
    Without knowing your form method (get or post) the generic answer is that your variables are in $_POST or $_GET. Thus the rudimentary code is:
    PHP Code:
    $x=$_POST['pid']; 
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0

    hii


    Originally Posted by gw1500se
    Without knowing your form method (get or post) the generic answer is that your variables are in $_POST or $_GET. Thus the rudimentary code is:
    PHP Code:
    $x=$_POST['pid']; 
    Tx for your reply.. there is no form method.. I want to do it on same page..
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,600
    Rep Power
    595
    You can't do PHP without a form. PHP only happens on the server side. The selections are done on the client side.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    3
    Rep Power
    0

    mhh


    Originally Posted by gw1500se
    You can't do PHP without a form. PHP only happens on the server side. The selections are done on the client side.
    is there any way i can pass the values in dropdownbox to php variable $x using jquery or java script??

    I tried javascript but i dont know how to pass the value to $x..

    I'm doing small school proj. client side and server both my self.. i know what u mean.. i dont want to use submit buton.. i need to change the value dynamically.. is it possible???
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,600
    Rep Power
    595
    What you are asking makes no sense. What PHP script are you trying to pass it to?
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  12. #7
  13. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    Javascript executes on the client computer, inside the browser.

    PHP executes on the server, through the PHP interpreter.

    You can only share data between these two computer systems using a POST or GET request. That's either from a full page action (clicking a link or submitting a form) or through AJAX (which simulates full page actions and returns the results to a javascript variable).

    Non-AJAX solutions are easier. If you're doing a school assignment, it will specify ajax if that's required.

    The new user guide has more information.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    720
    Rep Power
    7
    If your entire set of options is going to be a simple/short list, you can make your SELECT request before loading the page, and have it provide all values to the page, then have javascript adjust which are visible based on the drop-down.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    9
    Rep Power
    0
    Yes, what you are wanting to do is possible.

    What you'll have to do is not easy to explain, however.

    For one, you'll have to write a jquery function to tell when the user changes the value of the drop down.

    Then, you'll have the value of the dropdown go through an ajax query to call a php function to process that value. Once the function processes that server side, your ajax query will return whatever data your php function has come up with.

    Then you will have to be able to process that data and display it back into a part of your website.

    Hope that helps.

IMN logo majestic logo threadwatch logo seochat tools logo