In my application, i want to make a dynamic multi layer menu like this
Toy1
==>Sub toy1-a
==>Sub toy1-b
开发者_Go百科Toy2
==>Sub toy2-a
==>Sub toy2-b
Toy3
==Sub toy3-a
I have created 2 table in database called parent-Menu contain Toy1,Toy2,Toy3 and sub-Menu contain Sub toy1-a, Sub toy1-b and their father which it belongs. I don't know how to retrieve database or algorithm to make this. Anybody have solution ?
I can recommend you to use only one table, it will make your program very eaisy.
take 3 field *menu_id* , *menu_text* , *parent_id* for all top menu take parent id 1. now do the following work,
Retrieve all data from the table.
And use the recursive function to the place the menu.
精彩评论