作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
1) when types selected from dropdown his category and subcategory should be shown
in dropdown,problem : when we select types in category it is showing all the category
and all the subcategory of other types also
please solve this problem as soon as possible.
inventory_list.php
<select name="typ_id" id="typ_id">
<option>Select a Type</option>
<?php
$get_types = "select * from types";
$run_types = mysql_query($get_types);
while ($row_types=mysql_fetch_array($run_types)){
$typ_id= $row_types['typ_id'];
$typ_name = $row_types['typ_name'];
echo "<option value='$typ_id'>$typ_name</option>";
}
?>
<select name="cat_id" id="cat_id">
<option>Select a Category</option>
<?php
$get_category = "SELECT * FROM category ";
$run_category = mysql_query($get_category);
while ($row_category=mysql_fetch_array($run_category)){
$cat_id= $row_category['cat_id'];
$cat_name = $row_category['cat_name'];
echo "<option value='$cat_id'>$cat_name</option>";
}
?>
</select>
最佳答案
尝试下面的代码
<script>
function get_category(type_id){
$.ajax({
type: "POST",
url: "get_category.php",
data: { type_id : type_id }
}).done(function(data){
$("#category").html(data);
});
}
</script>
<select name="typ_id" id="typ_id" onchange="get_category(this)">
<option>Select a Type</option>
<?php
$get_types = "select * from types";
$run_types = mysql_query($get_types);
while ($row_types=mysql_fetch_array($run_types)){
$typ_id= $row_types['typ_id'];
$typ_name = $row_types['typ_name'];
echo "<option value='$typ_id'>$typ_name</option>";
}
?>
<div id='category'></div>
get_category.php
<?php
$get_category = "SELECT * FROM category where type_id = $_POST['type_id']";
$run_category = mysql_query($get_category);
echo '<select name="cat_id" id="cat_id">
<option>Select a Category</option>';
while ($row_category=mysql_fetch_array($run_category)){
$cat_id= $row_category['cat_id'];
$cat_name = $row_category['cat_name'];
echo "<option value='$cat_id'>$cat_name</option>";
}
echo '</select>';
?>
关于php - 当从下拉列表中选择类型时,他的类别和子类别应显示在下拉列表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27308749/
我是一名优秀的程序员,十分优秀!