gpt4 book ai didi

php - 在将数据插入书籍表时选择类别和子类别

转载 作者:行者123 更新时间:2023-11-30 00:54:21 25 4
gpt4 key购买 nike

我在书店网站上有三张 table 。类别、子类别和书籍我想在将数据插入图书表时选择类别和相关子类别,但子类别无法从类别中获取 ID,并且列表中未显示任何子类别我的代码如下:

<th scope="col">Select Category</th>
<th scope="col"><select name="cat">
<?php
include("config.php");
$catsql = "SELECT * FROM categories;";
$catres = mysql_query($catsql);
while($catrow= mysql_fetch_assoc($catres)) {
echo "<option value='" . $catrow['id']
. "'>" . $catrow['cat'] . "</option>";
}
?>

</select></th>
</tr>
<tr>
<th scope="col">Select Subcategory
</th>
<th scope="col"><select name="subcat">
<?php
$cat=$catrow['id'];
$subsql="select * from subcat where catid=$cat;";
$subrs=mysql_query($subsql);
while($subrow=mysql_fetch_array($subrs)){
echo "<option value='" . $subrow['id']
. "'>" . $subrow['subcat'] . "</option>";

}
?>
</select>
</th>

最佳答案

当用户选择任何类别来填充子类别下拉列表时,您应该使用 Ajax 调用。

关于php - 在将数据插入书籍表时选择类别和子类别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20717331/

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