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>
0
A
回答
0
嘗試下面的代碼
<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>';
?>
+0
從下拉菜單中選擇類型後,下拉菜單不會出現,什麼是類別的html。 – 2014-12-05 08:42:40
+0
使用平變化= 「get_category(THIS.VALUE)」,而不是平變化= 「get_category(這)」 和不要忘記包括jquery的文件 – manuyd 2014-12-05 09:20:44
+0
inventory_list.php
請查看教程MySQL查詢與WHERE條件。 https://www.google.co.in/?gfe_rd=cr&ei=AzaBVNihLtLAuASLo4GgDw&gws_rd=ssl#q=mysql+select+with+condition – Chandresh 2014-12-05 04:36:27
你也可以參考這個鏈接相同:http://stackoverflow.com/questions/20795351/dynamic-dropdownlist-value-from-database/20795573#20795573 – Chandresh 2014-12-05 04:38:47