Hey guys,
I have this code which grabs categories from my category table of the database and populates the category drop-down box. I was hoping someone could tell me how I could populate the second drop-down box depending on what was selected in the first box.
E.g. If "Networking" is selected in the first box, then the second drop-down displays the subcategories of networking such as "wireless", "bluetooth" etc. Is it possible to do this in PHP alone? Or would I need to use javascript? How can I achieve this functionality?
Thanks
<?php
require ('db.php');
$query = "SELECT c_id, c_category FROM category WHERE c_id BETWEEN '1' AND '11'";
$result = mysql_query($query);
$options= "";
while ($row=mysql_fetch_array($result)) {
$ctgid = $row["c_id"];
$category = $row["c_category"];
$options.="<option value = \"$ctgid\">".$category."</option>";
}
?>
<html>
<head>
</head>
<body>
<select name="category" size="10px">
<option value="">--Select a Category--
<?= $options ?>
</select>
<select name="subcategory" size="10px">
<option value="">--Select a Subcategory--
<?= $options ?>
</select>
</body>
</html>