Hi, I have an issue that I think you could help me with.
I would like to make so that when I select something in my select box (my main category) a sub category for that will appear based on my selection in the main category.
I assume you would use AJAX for this as I have searched a bit but I can't get it to function with my script.
My MySQL looks like this:
CREATE TABLE main_categories (
ID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(ID),
main_category varchar(250) UNIQUE
)
CREATE TABLE sub_categories (
ID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(ID),
sub_category varchar(250),
main_category varchar(250)
)
My PHP is like this so far:
<form>
<p>Item Main Category:<br/>
<select name="mc" class="f" />';
$cat = mysql_query("SELECT * FROM main_categories ORDER BY main_category",$connect) or die(mysql_error());
while($row = mysql_fetch_array($cat))
{
echo '<option value="'.$row[ID].'">'.$row[main_category].'</option>';
}
echo '</select></p><p>
<select name="sc" class="input" id="sc" onchange="listUpdate(this.value)">
<option value="Please Select">Please Select</option>';
$scat = mysql_query("SELECT * FROM sub_categories ORDER BY sub_category",$connect) or die(mysql_error());
while($row = mysql_fetch_array($scat))
{
echo '<option value="'.$row[ID].'">'.$row[sub_category].'</option>';
}
echo '</select></p><p>
<select name="scc" class="input" id="scc" onchange="listUpdate(this.value)">
<option value="Please Select">Please Select</option>';
$scat = mysql_query("SELECT * FROM sub_sub_categories ORDER BY sub_sub_category",$connect) or die(mysql_error());
while($row = mysql_fetch_array($scat))
{
echo '<option value="'.$row[ID].'">'.$row[sub_sub_category].'</option>';
}
echo '
</select>
</p>
<p>Item name:<br/><input type="text" /></p>
<div id="model_id"></div>
</form>