我需要创建2个投递箱
答案 0 :(得分:1)
使用ajax,它可能是这样的
您的HTML
<select id="combo1" name="combo1" onchange="getvaluesforcombo2($('#combo1').val());">
<option value=""></option>
<option value="1">Computer</option>
<option value="2">Mobile</option>
</select>
<select id="combo2" name="combo2">
<option value=""></option>
</select>
您的JS
function getvaluesforcombo2(valuec1) {
var postData = {combo1v:combo1v};
$.post('getvaluefor2.php', postData, function(data) {
var obj = $.parseJSON(data);
var sel = $("#combo2");
sel.empty();
sel.append('<option value=""></option>');
$.each(obj, function(k, v){
sel.append('<option value="'+v.Code+'">'+v.Name+'</option>');
});
});
}
和您的PHP
if(isset($ _ POST [&#39; combo1&#39;])){ $ combo1 = $ _POST [&#39; combo1&#39;];
$query= $this->db_connection->prepare('SELECT type, name FROM mobileandpcbrands WHERE type = :combo1');
$query->bindValue(':combo1', $combo1, PDO::PARAM_INT);
$query_pilar->execute();
//if there is results
if ($query->rowCount() != 0) {
$result = $query->fetchAll();
foreach ($result as $results) {
$rows[] = $results;
}
echo json_encode($rows);
}
这是一个例子,我希望这可以帮助你