数据库(data.mdb)其包含两个表BigSort(大类)和SmallSort(小类) 字段: BigSort:BigSort_ID(自动编号)、BigSort_Name(文本)、Rank(数字)
SmallSort:SmallSort_ID(自动编号)、BigSort_ID(数字)、SmallSort_Name(文本)、Rank(数字)
自己添几个记录,注意两个表中的BigSort_ID要一至啊。
实现代码:
'************************************************************************************************************
conn.asp数据库连接文件代码: <% dim conn '数据库连接 dim connstr '连接字符串 dim db '数据库文件路径
db = "data.mdb" connstr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & Server.MapPath(db) Set conn = Server.CreateObject("ADODB.Connection") If Err Then Err.Clear Set Conn = Nothing Response.Write "数据库连接出错,请打开conn.asp文件检查连接字串。" Response.End End If
conn.Open connstr %>
'********************************************************************************************************** List.asp代码: <!--#include file="Conn.asp" --> <SCRIPT language="javascript"> <!-- function showmenu_item(sid) { which = eval("menu_item" + sid); img = eval("sub_" + sid); if (which.style.display == "none") { eval("menu_item" + sid + ".style.display=\"\";"); eval("sub_" + sid + ".src=\"Images/open.gif\";"); }else{ eval("menu_item" + sid + ".style.display=\"none\";"); eval("sub_" + sid + ".src=\"Images/close.gif\";"); } }
//--> </SCRIPT> <table width="100%" border="0" cellpadding="0" cellspacing="1" class="Table_Border"> <tr> <td class="Table_Title_Bg">栏目导航</td> </tr> <% Set Rs1=conn.Execute("Select*From BigSort Order By Rank") Do While Not Rs1.Eof Set Rs=conn.Execute("Select Count(*) As Total From SmallSort Where BigSort_ID="&Rs1("BigSort_ID")&"") If Rs("Total")>0 Then %> <tr onClick="showmenu_item(<%=Rs1("BigSort_ID")%>)" style="cursor:hand;" onMouseOver="this.style.backgroundColor='#EFEFEF'" onMouseOut="this.style.backgroundColor=''" bgcolor="#FFFFFF"> <td style="text-indent:10px;" height="20px;"><img id="sub_<%=Rs1("BigSort_ID")%>" src="Images/close.gif" align="absmiddle"> <%=Rs1("BigSort_Name")&"("&Rs("Total")&")"%></td> </tr> <%Else%> <tr style="cursor:hand;" onMouseOver="this.style.backgroundColor='#EFEFEF'" onMouseOut="this.style.backgroundColor=''" bgcolor="#FFFFFF"> <td style="text-indent:10px;" height="20px;"><img src="Images/close.gif" align="absmiddle"><%=Rs1("BigSort_Name")%></td> </tr> <% End If Set Rs=Nothing %> <tr id='menu_item<%=Rs1("BigSort_ID")%>' style="display:none"> <td style="text-indent:10px;"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <% Set Rs=conn.Execute("Select*From SmallSort Where BigSort_ID="&Rs1("BigSort_ID")&" Order By Rank") Do While Not Rs.Eof %> <tr onMouseOver="this.style.backgroundColor='#EFEFEF'" onMouseOut="this.style.backgroundColor=''" bgcolor="#FFFFFF"> <td style="text-indent:20px;height:20px;cursor:hand;"><img src="Images/close.gif" align="absmiddle"> <%=Rs("SmallSort_Name")%></td> </tr> <% Rs.Movenext Loop Set Rs=Nothing %> </table> </td> </tr> <% Rs1.Movenext Loop Set Rs1=Nothing %> </table>
'****************************************************************************************************************************** big.asp修改大类的代码:
<!--#include file="Conn.asp" --> <% Dim menu,BigSort_ID,BigSort_Name menu=Request("menu") BigSort_ID=Cint(Request("BigSort_ID")) BigSort_Name=Trim(Request("BigSort_Name")) If menu="" Then %> <form id="form" name="form" method="post" action="?menu=Saveadd"> <table width="100%" border="0" cellspacing="1"> <tr> <td>类别名称: <input name="BigSort_Name" type="text" id="BigSort_Name"> <input type="submit" name="Submit" value="添加"></td> </tr> </table> </form> <% Set Rs=conn.Execute("Select*From BigSort Order By Rank") Do While Not Rs.eof %> <form id="form<%=Rs("BigSort_ID")%>" name="form<%=Rs("BigSort_ID")%>" method="post" action="?menu=Saveedit&BigSort_ID=<%=Rs("BigSort_ID")%>" style="margin:0px;"> <table width="100%" border="0" cellspacing="1"> <tr> <td><input name="BigSort_Name" type="text" id="BigSort_Name2" value="<%=Rs("BigSort_Name")%>" /> <input type="submit" name="Submit" value="修改" /> <input type="button" name="Submit2" value="删除"onClick="if(confirm('你确定删除该栏目吗?'))location.href='?menu=Delete&BigSort_ID=<%=Rs("BigSort_ID")%>'"></td> </tr> </table> </form> <% Rs.movenext loop set Rs=nothing
ElseIf menu="Saveadd" Then conn.Execute("insert into BigSort(BigSort_Name) values ('"&BigSort_Name&"')") Response.Redirect "?"
ElseIf menu="Saveedit" Then conn.execute("Update BigSort Set PBigSort_Name='"&BigSort_Name&"' Where BigSort_ID="&BigSort_ID&"") Response.Redirect "?"
ElseIf menu="Delete" Then conn.Execute("Delete From BigSort Where BigSort_ID="&BigSort_ID) conn.Execute("Delete From SmallSort Where BigSort_ID="&BigSort_ID) Response.Redirect "?"
End If %>
'********************************************************************************************************** small.asp修改小类的代码
<!--#include file="Conn.asp" --> <% Dim menu,BigSort_ID,SmallSort_ID,SmallSort_Name menu=Request("menu") BigSort_ID=Cint(Request("BigSort_ID")) SmallSort_ID=Cint(Request("SmallSort_ID")) SmallSort_Name=Trim(Request("SmallSort_Name")) If menu="" Then Set Rs1=conn.Execute("Select*From BigSort Order By Rank") If Not Rs1.Eof Then %><table width="100%" border="0" cellspacing="1"> <tr> <td>大类别:</td> </tr> <tr> <td> <% Do While Not Rs1.eof %>【<a href="?BigSort_ID=<%=Rs1("BigSort_ID")%>"><%=Rs1("BigSort_Name")%></a>】 <% Rs1.movenext Loop %> </td> </tr>
</table>
<form id="form" name="form" method="post" action="?menu=Saveadd"> <table width="100%" border="0" cellspacing="1"> <tr> <td>【 <% If BigSort_ID=0 Then Response.Write conn.Execute("Select Top 1 BigSort_Name From BigSort")(0) BigSort_ID=conn.Execute("Select Top 1 BigSort_ID From BigSort")(0) Else Response.Write conn.Execute("Select BigSort_Name From BigSort Where BigSort_ID="&BigSort_ID)(0) End If %> 】子类别名称: <input name="SmallSort_Name" type="text" id="SmallSort_Name"> <input name="BigSort_ID" type="hidden" value="<%=BigSort_ID%>"> <input type="submit" name="Submit" value="添加"></td> </tr> </table> </form> <% Set Rs=conn.Execute("Select * From SmallSort Where BigSort_ID="&BigSort_ID) Do While Not Rs.eof %> <form id="form<%=Rs("SmallSort_ID")%>" name="form<%=Rs("SmallSort_ID")%>" method="post" action="?menu=Saveedit&SmallSort_ID=<%=Rs("SmallSort_ID")%>&BigSort_ID=<%=BigSort_ID%>" style="margin:0px;"> <table width="100%" border="0" cellspacing="1"> <tr> <td><input name="SmallSort_Name" type="text" id="Small_Name" value="<%=Rs("SmallSort_Name")%>" /> <input type="submit" name="Submit" value="修改" /> <input type="button" name="Submit2" value="删除"onClick="if(confirm('你确定删除该栏目吗?'))location.href='?menu=Delete&SmallSort_ID=<%=Rs("SmallSort_ID")%>'"></td> </tr> </table> </form> <% Rs.movenext loop set Rs=nothing Else Response.Write "暂无大类" End If set Rs1=nothing
ElseIf menu="Saveadd" Then conn.Execute("insert into SmallSort (BigSort_ID,SmallSort_Name) values("&BigSort_ID&",'"&SmallSort_Name&"')") Response.Redirect "?"
ElseIf menu="Saveedit" Then conn.execute("Update SmallSort Set SmallSort_Name='"&SmallSort_Name&"' Where SmallSort_ID="&SmallSort_ID) Response.Redirect "?"
ElseIf menu="Delete" Then conn.Execute("Delete From SmallSort Where SmallSort_ID="&SmallSort_ID) Response.Redirect "?"
End If %>
|