January 17th, 2013, 09:23 AM
-
::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
!!
January 17th, 2013, 09:32 AM
-
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.
January 17th, 2013, 09:35 AM
-
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..
January 17th, 2013, 09:47 AM
-
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.
January 17th, 2013, 09:53 AM
-
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???
January 17th, 2013, 10:00 AM
-
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.
January 17th, 2013, 10:44 AM
-
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.
January 17th, 2013, 10:58 AM
-
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.
January 18th, 2013, 12:59 AM
-
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.