onchange select做不同的mysql查询

Mar*_*sic 3 html php jquery

标题说我需要onchange的帮助.我有select标签,当我从选择列表中选择一些东西时,我需要做不同的mysql查询.例:

<select name="list">
<option>cars</option>
<option>busses</option>
<option>trucks</option>
</select>
Run Code Online (Sandbox Code Playgroud)

然后当我选择cars它时这样做

$query="select * from table where type='cars'";
Run Code Online (Sandbox Code Playgroud)

如果我选择trucks它呢

$query="select * from table where type='trucks'";
Run Code Online (Sandbox Code Playgroud)

等等...
然后我需要在列表示例下显示div中的结果

<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> 
Run Code Online (Sandbox Code Playgroud)

请帮忙!!!

Ema*_*aki 6

如果要通过ajax更改结果:

HTML:

 <select id="list" name="list">

    <option>cars</option>

    <option>busses</option>

    <option>trucks</option>
    </select>
Run Code Online (Sandbox Code Playgroud)

在JS文件中:

$(document).ready(function() {
  $('#list').change(function() {
var selected=$(this).val();
  $.get("change_query.php?selected="+selected, function(data){
      $('.result').html(data);

    });
    });
});
Run Code Online (Sandbox Code Playgroud)

并且您应该在其中创建change_query.php文件以及您的查询和代码并将结果返回到其中

$type = $_POST["selected"];

$query="select * from table where type='".$type."'";
Run Code Online (Sandbox Code Playgroud)

在这里打印结果....;

  • 告诉我,如果你需要任何帮助,我只是引导你进入Jquery而不是所有代码