Using ASP and database to implement the pop-up menu with unlimited series

Source: Internet
Author: User
Tags implement include trim
Menu | data | Database <!--#include virtual= ' include/database.asp '-->
<%
Set Rs=server.createobject ("ADODB. RecordSet ")

Sql= "Select Menu_name, Menu_link, Menu_bgcolor, menu_color,id from enter_individual WHERE (parent_id = (select IDs from ENT er_individual WHERE menu_flag = ' root ') "' Query gets root node
Rs. Open sql,conn,1,1
Response.Write "< table width=100% border=0 cellspacing=1 cellpadding=0 align=center>< tr bgcolor= #3399CC Valign=bottom align=center> "
Sumnum=rs. RecordCount
Myarray=rs. GetRows ()
Rs. Close ()
Widd=780/sumnum ' from the first Level submenu number to determine the pop-up menu x-coordinate increment pixel
Dim i
I=0
Defaultbgcolor= "#3399cc" ' specifies the default background color
Defaultcolor= ' #ffffff ' specifies the default font color
defaultlink= "#" to specify a default link
Posit_x=0 ' x position
Flag=1 ' flag, as menu pop-up direction 1 indicates right, 0 indicates left
' Response.Write MyArray (4,6)
While I Response.Write "< TD height=20 Bgcolor=" &myarray (2,i) & "Width=" &widd& ">< a href=" & MyArray (1,i) & "Onmouseover=java script:a" &myarray (4,i) & ". Style.display= ' block ' Onmouseout=java script: A "&myarray (4,i) &". style.display= ' None ' >< font color= "&myarray (3,i) &" > "&myarray (0,i) & "</a></td>"
'-----------------------------------------------

I=i+1
Wend
Response.Write "</tr></table>"

I=0
While I posit_y=100 ' y position back in place


If i>= (SUMNUM/2) Then ' If the menu goes to the right half, the pop-up turns
Flag=0
End If

' Call the GetSubMenu function to set the subordinate menu of the first-level menu to MyArray (4,i), which is the ID of the div that contains the subordinate menu.

GetSubMenu myarray (4,i), posit_x,posit_y
Posit_x=posit_x+widd ' The X coordinate value of the submenu of the next level menu is increased by one unit
I=i+1

Wend

' Functions to subordinate menus using a recursive algorithm
' parent_id parent ID; Posit_x the left position of the pop-up layer; Posit_y the ejection layer from the above position;

Function GetSubMenu (parent_id,posit_x,posit_y)
Dim myarray
Dim sumnum
Dim i

' Query submenu sub-menu
Sql= "Select Menu_name, Menu_link, Menu_bgcolor, menu_color,id from enter_individual WHERE parent_id =" &parent_id& amp; " and user_id = ' "&userid&" "
Rs. Open sql,conn,1,1

' If the subordinate menu does not exist, reduce the number of layers, close the database link, create an empty layer with the parent ID as the div ID, and then return
If Rs. Eof=true Then
Level=level-1
Rs. Close ()
' Response.Write parent_id
Response.Write "< div id= ' a" &parent_id& "' style= ' position:absolute; Top:4; Left:-1; Display:none; width:0; height:0 ' ></div> '
Else

' If there is access to database data and call Setsubmenu display menu
Sumnum=rs. RecordCount
Myarray=rs. GetRows ()
Rs. Close ()
Setsubmenu myarray,sumnum,parent_id,posit_x,posit_y

' Loop the data, the recursive call GetSubMenu
I=0
While i< Sumnum
Posit_y=posit_y*1+20 ' recursive posit_y plus a unit,
If Level=0 Then ' if the progression is reduced to 0 then return to 1
Level=1
End If
' If flag=1 Then
' GetSubMenu myarray (4,i), posit_x+level*widd,posit_y-level*20 ' recursive call getsubmenu x,y coordinate extension level unit
' End If
If flag=0 Then
GetSubMenu myarray (4,i), posit_x-level*widd,posit_y-level*20 ' recursive call getsubmenu x,y coordinate extension level unit
Else
GetSubMenu myarray (4,i), posit_x+level*widd,posit_y-level*20 ' recursive call getsubmenu x,y coordinate extension level unit
End If

I=i+1
Wend
End If

End Function

' Set child menu function
' myarray menu data, sumnum array size, parent_id layer ID;
' Posit_x the left position of the pop-up layer; Posit_y the ejection layer from the above position;

Function Setsubmenu (myarray,sumnum,parent_id,posit_x,posit_y)
Dim i
Parent_id= "A" &parent_id ' parent menu ID preceded by a as the layer ID
Hh=sumnum*20 ' array size multiplied by 20 as the height of the layer
Response.Write "< DIV Onmouseover=java script:" &parent_id& "style.display= ' block ' Onmouseout=java script: "&parent_id&" style.display= ' None ' id= ' "&parent_id&" ' style= ' position:absolute; Top: "&posit_y&"; Left: "&posit_x&"; Height: "&hh*1&"; Width: "&widd&"; Display:none;vertical-align:top ' >< table width=100% border=0 cellspacing=1 cellpadding=0 > '
I=0
While I

MyArray (0,i) =trim (MyArray (0,i))
MyArray (1,i) =trim (MyArray (1,i))
MyArray (2,i) =trim (MyArray (2,i))
MyArray (3,i) =trim (MyArray (3,i))


If myarray (2,i) = "" Then
MyArray (2,i) =defaultbgcolor
End If

If myarray (3,i) = "" Then
MyArray (3,i) =defaultcolor
End If

If myarray (1,i) = "" Then
MyArray (1,i) =defaultlink
End If


Response.wri



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.