Hi everyone,
I am still pretty green it the whole mysql/php stuff...
I'm creating an admin page where the user will update a record in the database. The database contains 3 tables. One table is a Category table with the Category ID, Parent Category ID, and Category Name. I want to show this list as a drop down menu item within the update form. So far, I have it so all the categories display within the form box, but it displays from the top of the tree, not from the actual category for that record. So what it does now is: (I've simplified the categories for this display)
Fruit:Apple
Fruit😛ear
Vegetable:Broccoli
Vegetable:Spinach
Regardless of what category the record actually corresponds to, the display starts at the top of the tree. I've tried figuring out how to put the "select" portion in so the right category shows in the window for the record, (so if our record had the category Vegetable:Spinach, that is what would display in the window)
but then the user could click on the drop down menu icon and change the category for that record. Here is my current function that displays the categories:
<?php
function printlist($parent_id, $parent_desc) {
mysql_select_db($database_conn_test, $conn_test);
$result = mysql_query("SELECT NAME, CID FROM category WHERE PARENT=$parent_id") or die("ERROR");
$numres = mysql_num_rows($result);
for($i=0;$i<$numres;$i++) {
$section_name = mysql_result($result, $i, "NAME");
$section_id = mysql_result($result, $i, "CID");
$cat_id = mysql_result($result, $i, "CID");
echo ("<option value=\"$cat_id\">$parent_desc" . "$section_name </option><br>\n");
printlist($section_id, $parent_desc ."$section_name:");
}
}
?>
Then, in the form I have:
<td><select name="CID">
<?php
printlist (0, "");
?>
</select> </td>
This works fine for showing the whole tree from the top, but if anyone knows how I can make it show the whole tree, but the category for the current record to be the one displayed in the drop down window, I'd be unbelievably grateful. I've tried & tried, but keep getting all kinds of errors trying to add that piece of functionality.
THANKS for any help!!!