We need a dropdown-menu (<select><option>....), that outputs all the "categories" from the table "categories". When the function/script is called, you can see a dropdownmenu which recursively lists all categories. Like this:
This function/script will be placed on already existing page that is used to edit rows in the table "files". (for example [url removed, login to view] is used to call the row with the 'id' field set to 1). You get the idea.
So, what this piece of code needs to do besides listing all the categories inside a dropdownmenu, is to check what category, the current row that is being edited, is belonging to - And assign the attribute <option SELECTED> to that category name.
All entrys in the "files" table, has a 'category_id' field, that is linking the file to a category from the "category" table
Here is an example of the two tables, and how they look, and a User-Scenario of the achievment of this piece of code.
ID | parent_ID | name
1 | 0 | Category 1
2 | 1 | Category 1 - Part 1
3 | 1 | Category 1 - Part 2
ID | category_ID | name
1 | 2 | [url removed, login to view]
2 | 2 | [url removed, login to view]
3 | 3 | [url removed, login to view]
So, when editing the row with '[url removed, login to view]' (id=1), the dropdownmenu should already have selected what corresponds to category_ID=2, in other words; <option selected> Category 1 - Part 1 </option>
This should be very easy, and just to sum things up:
There is already a piece of code, named [url removed, login to view], that through text-fields gives the user the option to update the field 'name' on the row called to edit. So what this project will add, is a dropdownmenu that tells the user what category the file is allready in, (if it doesn't have a category assigned, the user should be able to assign one through the dropdownmenu) and then put that category as <option SELECTED>, so the user know what category the file belongs to.
Looking forward to be hearing from you.
Just to show what the final output should be like, when we edit mIRC.exe
<option value ="1">Category 1</option>
<option value ="2" SELECTED>...Category 1 - Part 1</option>
<option value ="3">...Category 1 - Part 2</option>
Note that the VALUE is set to the 'category_ID', so when updating the form, these values are sent.