onchange选择做不同的mysql查询 [英] onchange select do different mysql query
本文介绍了onchange选择做不同的mysql查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< select name =list>
< option>汽车< / option>
< option> busses< / option>
< option>卡车< / option>
< / select>
然后当我选择 cars
这个
$ query =select * from table where type ='cars';
如果我选择卡车
,它会执行
$ query =select * from table where type ='trucksters';
等等...
然后我需要显示结果在列表下的div
示例
< select name =list>
< option>汽车< / option>
< option> busses< / option>
< option>卡车< / option>
< / select>
< div>这是我需要显示查询结果< / div>
请帮忙!!!
解决方案
如果您想通过ajax更改结果:
HTML:
< select id =listname =list>
< option>汽车< / option>
< option>巴士< / option>
< option>卡车< / option>
< / select>
在JS文件中:
$(document).ready(function(){
$('#list')。change(function(){
var selected = $(this).val );
$ .get(change_query.php?selected =+ selected,function(data){
$('。result')。html(data);
});
});
});
,您应该创建change_query.php文件并在其中查询和代码并返回结果
$ type = $ _POST [selected];
$ query =select * from table where type ='。$ type。';
print result here;;
- 告诉我你是否需要任何帮助,我只是在Jquery中引导你而不是所有代码
As title says I need help with onchange. I have select tag,and I need to do different mysql query when I choose something from select list. Example:
<select name="list">
<option>cars</option>
<option>busses</option>
<option>trucks</option>
</select>
and then when i select cars
it do this
$query="select * from table where type='cars'";
and if I choose trucks
it do
$query="select * from table where type='trucks'";
and so on...
then I need to display the result in div under the list
example
<select name="list">
<option>cars</option>
<option>busses</option>
<option>trucks</option>
</select>
<div> this is where I need to display results from query</div>
Please help!!!
解决方案
If you want to change the result by ajax :
HTML :
<select id="list" name="list">
<option>cars</option>
<option>busses</option>
<option>trucks</option>
</select>
in JS File:
$(document).ready(function() {
$('#list').change(function() {
var selected=$(this).val();
$.get("change_query.php?selected="+selected, function(data){
$('.result').html(data);
});
});
});
and you should create change_query.php file and your query and code in it and return the result in it
$type = $_POST["selected"];
$query="select * from table where type='".$type."'";
print result here .... ;
- Tell me if you need any help ,I just guided you in Jquery not all code
这篇关于onchange选择做不同的mysql查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文