gpt4 book ai didi

php - 当从下拉列表中选择类型时,他的类别和子类别应显示在下拉列表中

转载 作者:行者123 更新时间:2023-11-29 23:20:57 33 4
gpt4 key购买 nike

  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/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com