PHP/MYSQL
<div style="width:810px; margin:inherit; padding-left:170px;">
<select style="width:300px;" id="n" name="userListingCateory">
<option disabled="disabled">Category...</option>
<?php while($row = $sth2->fetch(PDO::FETCH_ASSOC))
{echo "<option value=". $row['catID'] . ">" .$row['catName']."</option>";}
unset($sth2);
?>
</select>
<select style="width:340px;" id="n" name="userListingSubCateory">
<option disabled="disabled">Sub-Category...</option>
<?php while($row = $sth3->fetch(PDO::FETCH_ASSOC))
{echo "<option value=". $row['scatID'] . ">" .$row['scatName']."</option>";}
unset($sth3);
?>
</div>
</select>
上面的HTML获取两个表[Category]
和[SubCategory]
中的所有类别和子类别
点击[Category]
下拉菜单后需要运行的php/mysql看起来像:
SELECT scatID, scatName
FROM Category C, SubCategory SC
WHERE C.catID = SC.catID
AND C.catID = $origCatIDSelected;
我该如何获得sub-categories
,基于该category
进行选择?
在jquery/php中有什么简单的实现方法吗?
感谢
您可以使用执行AJAX函数的change((事件处理程序将当前选定的类别传递给包含查询数据库代码的PHP文件,然后通过jQuery中AJAX函数内置的成功回调将更新后的输出返回给客户端。
此外,您应该避免对多个对象使用相同的ID,因为ID属性是唯一的。