To create a dynamic menu from database, you can input some condition clause using either CGI (asp, php, etc.) or JavaScript language, that is, to input the Prefix or Suffix for a menu item in the Item Condition dialog.
First, download this ASP database sample
here.
Then unzip and install all the files to a web server that supports ASP (Active
Server Pages) so you can view it.
As you see, in this sample, the menu contains two levels: the parent level showing
the product categories and the sub level showing the specific products. Actually,
there are only two menu items, one in the parent level and the other is in the
sub level.
The final result that you are seeing is just got from database.
The following are the steps of this example:
(Before creating the menu, you should make a database containing the information
of the product categories and the specific products.)
Note: Normally in order to optimize the menu code, if several menu items have the same property, only one item's property code is recorded and other items take reference of its property code. If we add a condition to this item, there is possibility that it will be invisible when its condition is not met. And its property code can not be referenced by other items either. This will cause the whole menu can not work correctly. Please do check "This item may be invisible at run-time" to avoid the problem.
This is the source code at the beginning of this sample page.
Code |
Explanation |
<%Option Explicit%> | |
<% Dim Dbq, Dsn, Dc Dim rsCat, rsProduct Dim sCatName, sProduct, sLink Dbq = Server.MapPath(".\") & "\products.mdb;" Dsn = "driver={Microsoft Access Driver (*.mdb)};pwd=;Dbq=" & Dbq Set Dc = Server.CreateObject("ADODB.Connection") Dc.Open Dsn Set rsCat = Dc.Execute("SELECT * FROM CATEGORY") %> |
After you add item condition and edit the menu item, DHTMLMenu inserts following
code into the page. The entire source code below is generated by DHTMLMenu program.
Your editing of conditions will be saved in the menu's configuration file (*.pgt),
which can be edited again. To learn further what the code represents,
please read the following code explanation:
Code |
Explanation |
stm_bm(["uueoehr",400,"".....) | The code for the beginning of the whole menu |
stm_bp("p0",[0,4,0,0,3,1,0,0,100,"",-2...... ) | The code for the group of popup menu items |
<% |
|
stm_ai("p0i0",[1,"<%=rsCatName%>","",.....) | The code for menu item "<%=rsCat(Name)%>" |
stm_bpx("p1","p0",[1,4,0,-1,.....) | Suffix of the menu item "<%=rsCat(Name)%>" (This code is optimized according to an existing menu item which has the same properties in parts as the new one.) |
|
|
stm_ai("p1i0",[1,"<%=sProduct%> .....) | The code for menu item "<%=sProduct%>" |
|
|
 stm_ep() | The code for an appended item Separator |
|
|
stm_ep() | The code for the end of popup menu items |
stm_em() | The code for the end of the whole menu |