madmatter23
09-05-2007, 01:58 AM
I am very familiar with php but I don't know javascript very well at all, and I suspect I may need to know some for this, so I'm looking for some pointers.
I need to create a set of nested drop down menus that populate using data from a mysql database.
So here's an example.
Drop down menu #1
<select name="category">
<?php
$querylist = "SELECT category FROM categories ORDER BY category ASC";
$list = mysql_query($querylist, $dbc);
echo "<option selected value=\"Select a Category\">Select a Category</option>";
while (list($categories) = mysql_fetch_row($list)) {
echo "<option> $categories </option>";
}
?>
</select>
Then when the user selects a category, I want a second drop down menu with relevant subcategories to appear. It will query the mysql database similarly:
<select name="subcategory">
<?php
$querysublist = "SELECT subcategory FROM subcategories WHERE parent='$category' ORDER BY subcategory ASC";
$sublist = mysql_query($querysublist, $dbc);
while (list($subcategories) = mysql_fetch_row($sublist)) {
echo "<option> $subcategories </option>";
}
?>
Etc. In the end I'd like 3 menus: categories, subcategories, and subsubcategories.
I'm just not quite sure how to make the code recognize that when menu 1 isset, it must then create and populate menu 2, etc.
I'm guessing that I should set php functions to be executed onChange, but I'm not sure how to pass the selection back to the subcategories function, and then make the subcategories function execute correctly.
If anyone has any ideas about how to make this work, I would very much appreciate the advice.
Thank you.
I need to create a set of nested drop down menus that populate using data from a mysql database.
So here's an example.
Drop down menu #1
<select name="category">
<?php
$querylist = "SELECT category FROM categories ORDER BY category ASC";
$list = mysql_query($querylist, $dbc);
echo "<option selected value=\"Select a Category\">Select a Category</option>";
while (list($categories) = mysql_fetch_row($list)) {
echo "<option> $categories </option>";
}
?>
</select>
Then when the user selects a category, I want a second drop down menu with relevant subcategories to appear. It will query the mysql database similarly:
<select name="subcategory">
<?php
$querysublist = "SELECT subcategory FROM subcategories WHERE parent='$category' ORDER BY subcategory ASC";
$sublist = mysql_query($querysublist, $dbc);
while (list($subcategories) = mysql_fetch_row($sublist)) {
echo "<option> $subcategories </option>";
}
?>
Etc. In the end I'd like 3 menus: categories, subcategories, and subsubcategories.
I'm just not quite sure how to make the code recognize that when menu 1 isset, it must then create and populate menu 2, etc.
I'm guessing that I should set php functions to be executed onChange, but I'm not sure how to pass the selection back to the subcategories function, and then make the subcategories function execute correctly.
If anyone has any ideas about how to make this work, I would very much appreciate the advice.
Thank you.