怎么样将你的代码与数据库结合来做动态的二级菜单?也就是一级菜单a,b,c都是从数据库中取得,那么下面的第二级也是根据附属的第一级菜单来取得的,我用的上面的代码修改但是怎么不行,请指教,谢谢!
请教yms123:
yms123你好!非常感谢你的答复,但是我为了好看一些,进行了修改,但是修改后拿取出来的子菜单却只能显示第一条,其他的不能显示,本来用response来看是有三条的。请帮忙,谢谢!代码如下:
<%
dim cn,rs,tablenum,strMenuID,I,J,strSonMenu
set cn = Server.CreateObject("Adodb.Connection")
cn.open "Provider=SQLOLEDB.1;Password=;Persist Security Info=True;User ID=sa;Initial Catalog=lctdata;Data Source=localhost"
Set rs = Server.CreateObject("Adodb.Recordset")
Set rs1 = Server.CreateObject("Adodb.Recordset")
'rs.open "select A.*,B.* from Menu_Role A,Menu_Info B where Role_User='" & strLoginName & "'",cn,1,3
rs.open "select A.*,B.* from Menu_Role A,Menu_Info B where A.Role_ID=B.Menu_ID and Parent_id=0 and A.Role_User='" & strLoginName & "'",cn,1,1
%>
<html>
<head>
<title>无标题文档</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language=javascript>
function ShowLayer(index)
{
if(this.Layer(index).style.display=="none")
{
this.Layer(index).style.display="block";
}
else
{
this.Layer(index).style.display="none";
}
}
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="">
<table width="41%" border="0" height="116" id="table1">
<%
if not rs.eof then
rs.movefirst
for I=1 to rs.recordcount
strSonMenu = rs("menu_id")
%>
<tr>
<td><a href=# onclick=ShowLayer(0);><%=rs("menu_name")%>菜单一</a></td>
</tr>
<%
response.write strSonMenu
if rs1.state=1 then rs1.close
rs1.Open "select * From menu_info Where Parent_id='" & strSonMenu & "'",cn,1,1
IF Not rs1.EOF Then
for j=1 to rs1.recordcount
%>
<tr>
<td>
<div style=display:none; id=Layer><img src="child.gif"><%=rs1("menu_name")%></div>
</td>
</tr>
<% rs1.MoveNext
next
End IF
rs.MoveNext
next
end if%>
</table>
</form>
</body>
</html>