Asp教程

通过asp实例结合结合ACCESS,MSSQL来更好的深入Asp学习 - 爬坡者

« 三级联动下拉列表[数据库版]ASP生成彩色可变长验证码程序 »

ASP无限级分类实现源码

<% 
    '程序的核心是一个数组,显示的结果只是比较常见的两种情况,只读取了一次数据库 
    Dim LID,CID,TID,OID,Tmp,Url,Bof,Eof,i,ReadSQL,PgNum,PgSiz,Arr,reID,AllRs,LinkStr, 
    ReadPgSiz,ReadPgNum,ReadAllFd,ReadAllPg,ReadAllRs,ReadRsNum 
     Db = "test.mdb" 
     ConnStr = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & Server.MapPath(db) 
     Set conn = Server.createObject("ADODB.Connection") 
     conn.open ConnStr 
    Set NET = New Class_NET   
    Class Class_NET 
     function Read(ReadSQL,PgNum,PgSiz) 
     ReadSQL =(Replace(ReadSQL,"'","")) 
     ReadPgSiz=Int(PgSiz) 
     ReadPgNum=Int(PgNum) 
     Set ReadRs= Server.createObject("ADODB.Recordset") 
     ReadRs.open ReadSQL,conn,1,1 
     ReadRs.PageSize =ReadPgSiz 
     ReadAllFd =ReadRs.Fields.Count 
     ReadAllPg =ReadRs.PageCount 
     ReadAllRs =ReadRs.RecordCount 
     ReadRsNum =ReadRs.Absoluteposition 
     If int(ReadPgNum)>Int(ReadAllPg) or int(ReadPgNum)=0 Then ReadPgNum=1 
     ReadRs.absolutepage=ReadPgNum 
     '返回实际的页面记录条数 
     If int(ReadPgNum)=Int(ReadAllPg) Then ReadPgSiz=ReadAllRs-ReadPgSiz*(ReadAllPg-1) 
     '数组开始 
     reDim ReadRsArr(ReadAllFd-1,ReadPgSiz-1) 
     For ReadArrRs = 0 to ReadPgSiz-1 
     If ReadRs.Eof Then Exit For 
     For ReadArrFd = 0 to ReadAllFd-1 
     ReadRsArr(ReadArrFd,ReadArrRs)=ReadRs(ReadArrFd) 
     Next 
     ReadRs.MoveNext 
     Next 
     Read=ReadRsArr 
     End function 
    '===================================================== 
     function ClassPath(Arr,reID,AllRs,Url,LinkStr) 
     Tmp=Null 
     reID=Int(reID) 
     If reID=0 Then Exit function 
     For i=0 to AllRs-1 
     If int(Arr(5,i))=int(reID) Then 
     OID=Arr(0,i) 
     LID=Arr(1,i) 
     Exit For 
     End If 
     Next 
     For i=i to 0 step -1 
     If Arr(1,i)<=LID Then 
     Tmp=LinkStr&"<a href="&Url&Arr(5,i)&">"&Arr(6,i)&"</a>"&Tmp 
     LID=LID-1 
     End If 
     Next 
     ClassPath=Tmp 
     End function 
    '===================================================== 
     Sub SetBofEof(Arr,reID,AllRs) 
     If reID=0 Then 
     Bof=0 
     Eof=AllRs-1 
     Else 
     For i=0 to AllRs-1 
     If Arr(5,i)=reID Then 
     Bof=i 
     For j=i+1 to AllRs-1 
     If Arr(1,j)<=Arr(1,i) Then 
     Eof=j-1 
     Exit For 
     End If 
     If j=AllRs-1 Then Eof=AllRs-1 
     Next 
     Exit For 
     End If 
     Next 
     End If 
     End Sub 
    '===================================================== 
     function ClassList(Arr,reID,AllRs,Url) 
     Tmp=Null 
     reID=Int(reID) 
     Call Net.SetBofEof(Arr,reID,AllRs) 
     '下边这两条实现不显示总分类的功能 
     If reID>0 Then Bof=Bof+1 
     For i=Bof to Eof 
     For j=1 to Arr(1,i)-Arr(1,Bof) 
     Tmp=Tmp&" " 
     Next 
     For k=i+1 to AllRs-1 
     If Int(Arr(2,k))=Int(Arr(2,i)) Then 
     Tmp=Tmp&"┝" 
     Exit For 
     Else 
     If k=AllRs-1 Then 
     Tmp=Tmp&"┕" 
     Exit For 
     End If 
     End If 
     Next 
     If i=AllRs-1 Then Tmp=Tmp&"┕" 
     Tmp=Tmp&"<a href="&Url&Arr(5,i)&">"&Arr(6,i)&"</a><br>" 
     Next 
     ClassList=Tmp 
     End function 
    End Class 
    Dim reClass 
     reClass=request("Class") 
     If reClass="" or Int(reClass)<1 Then reClass=0 
    Dim ClassArr 
     ClassArr=NET.Read(" select * From Class where LID<20 Order by OID",1,999) 
    Dim ClassAllRs 
     ClassAllRs=ReadAllRs 
    %> 
     <style type="text/css"> 
     <!-- 
     body,a,table,div,span,td,th,input,select{font-size:9pt;font-family:"dotuml";color:#000000;} 
     body {background-color:#ffffff;scrollbar-base-color:#d0d0c8} 
     a:hover{ color:#000000 ;} 
     a:link,a:active,a:visited{text-decoration:none ;color:#ff4500} 
     .btn {background-color: #d0d0c8; height: 21px; top: 1px; width: 21px; } 
     --> 
     </style> 
    <% 
    Response.Write "当前栏目的显示" 
    Response.Write "<br>" 
    Response.Write NET.ClassPath(ClassArr,reClass,ClassAllRs,"?Class=",">>>") 
    Response.Write "<br>" 
    Response.Write "栏目列表的显示" 
    Response.Write "<br>" 
    Response.Write NET.ClassList(ClassArr,reClass,ClassAllRs,"?class=") 
%》

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

最新评论及回复

最近发表

Powered By Z-Blog 1.8 Spirit Build 80710

Copyright 2007-2008 papozhe.com [asp教程] All Rights Reserved.
浙ICP备07030537号
免责申明:所有文章除特别声明,均来自网上,主要为学习用!内容仅供参考,版权归原作者。如侵犯您利益,请来信告知.
Email:papozhe$Gmail.com QQ:76336503