【发布时间】:2014-01-10 02:59:56
【问题描述】:
我在书店网站上有三张桌子。类别、子类别和书籍我想在将数据插入书籍表时选择类别和相关子类别,但子类别无法从类别中获取 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>
【问题讨论】: