"定义每页最大文章标题显示量MaxPerPage,你可以自己修改这里的数字来达到你的最佳显示效果 const MaxPerPage=18 dim totalPut dim CurrentPage dim TotalPages dim i,j
"假如返回的页面信息是空的,也就是如果你直接输入index.asp,那么就用这里定义的页数第一页 if not isempty(request("page")) then currentPage=cint(request("page")) else currentPage=1 end if dim sql dim rs dim rstype dim typesql dim typeid,typename
"如果返回的栏目信息为空,那么就用这里定义的栏目,这里指定的是第三个栏目 if not isEmpty(request("typeid")) then typeid=request("typeid") else typeid=3 end if
"通过返回的栏目typeid号,打开数据库显示指定的栏目,并把其值交给typename set rstype=server.createobject("adodb.recordset") typesql="select * from type where typeID="&cstr(typeid) rstype.open typesql,conn,1,1 typename=rstype("type") rstype.close %>
"打开指定的记录集article并按照文章的加入日期排序,在这里打开有两个条件,一个是利用like来查询数据库并显示相关文章标题,还有就是通过返回的typeid显示指定栏目的文章 <% sql="select * from article where title like '%"&request("txtitle")&"%' and typeid="+cstr(typeid)+" order by date desc" Set rs= Server.CreateObject("ADODB.Recordset") rs.open sql,conn,1,1
"如果查询数据库的结果指向记录集的开始或者结尾,表示数据库中没有任何相关文章 if rs.eof and rs.bof then response.write "<p align='center'>没有或没有找到任何文章</p>" else "如果数据库内有内容,则取得数据库内文章数目 totalPut=rs.recordcount "假如页面参数currentpage小于1,则指定为1 if currentpage<1 then currentpage=1 end if "利用文章总数和每页最大文章数算得分页的页数 if (currentpage-1)*MaxPerPage>totalput then if (totalPut mod MaxPerPage)=0 then currentpage= totalPut \ MaxPerPage else currentpage= totalPut \ MaxPerPage + 1 end if
end if "如果分页的页数为1或者页面数减1乘与页面最大文章数小于文章总数,则用已经做好的function showpage在showContent子程序也就是显示文章标题部分的上面和下面显示分页程序 if currentPage=1 then showpage totalput,MaxPerPage,"index.asp" showContent showpage totalput,MaxPerPage,"index.asp" else if (currentPage-1)*MaxPerPage<totalPut then rs.move (currentPage-1)*MaxPerPage "定义书签 dim bookmark bookmark=rs.bookmark showpage totalput,MaxPerPage,"index.asp" showContent showpage totalput,MaxPerPage,"index.asp" else currentPage=1 showpage totalput,MaxPerPage,"index.asp" showContent showpage totalput,MaxPerPage,"index.asp" end if end if rs.close end if
set rs=nothing "显示文章标题及相关数据库内容子程序 sub showContent dim i i=0