how to grab multiple (int) from title
I'm using $intVariable=(int)$_GET[var1];
to output and select a variable in mysql records i.e /myfile.php?cat=5
selects different results.
I am dealing with a dropdown from SQL so need to output a list based on selected ID's.. so I need to have something like /myfile.php?var1=X&var2=Y
I'm actually using a bit of JavaScript too, so unsure whether it's PHP or JS I need to adjust to grab another variable.
This code + some PHP curr开发者_如何学Pythonently outputs the selected ID of my selection in the title bar..
function reload(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
self.location='myfile.php?var1=' + val ;
}
How do I achieve this multi tier structure getting 2 variables from the title, so I can use multiple variable to assign in my MYSQL selects. have tier dropdown lists
Not really sure what exact answer your looking for, but to fix your function to add more vars:
function reload(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
self.location='myfile.php?var1=' + val + '&var2=' + val2;
}
In general:
what your setting there is the GET parameters in the URL, so for example to set the variables "name" and "age" you would do:
http://www.example.com?name=bob&age=17
Where name is bob and age is 17
The other way people do it is through html arrays, so:
http://www.example.com?people[]=bob&people[]=fred
On the php side, $_GET['people'] will return an array with the two strings bob and fred.
If your using javascript to construct the url, you need to js to create a url like the one above, I'm guessing it should return
self.location='myfile.php?var1='+val+'&var2='+val2
When your reloading the form, to retain the selected drop down, you need to do one of two things
JS: Recommended
$('#mySelect').val(val2)
or in the php
if($optionvalue == $val2){$selected = "selected"}
echo "<option value=\"$optionvalue\" $selected>myoption</option>"
Actually what you need is both PHP and javascript i think. You should pass another variable
function reload(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
var val2 = //get the value for var 2
self.location='myfile.php?var1=' + val +'&var2='+ val2 ;
}
and then get it in php
$intValue2= (int)$_GET['var2']
and use it for mysql
精彩评论