|
楼主
|     发布时间:  点击:75次 |
作者:凉风
发表: 195篇
回复: 737篇
QQ: 84207336
|     麻烦老师帮解析一下该分页程序 在网上有很多人常用这样一个分页程序,但我有一些不太明白,望老师解答一下~!
-------Html页面显示部分------
<%
'设置每页显示记录为20条,超过20条就分页显示
const MaxPerPage=20
'定义信息记录总数
dim totalPut
'定义当前页码
dim CurrentPage
'定义总页码数
dim TotalPages
dim i,j
'首次打开网站时,令其为第一页
if not isempty(request("page")) then
currentPage=cint(request("page"))
else
currentPage=1
end if
%>
-------Html页面显示部分------
<%
dim sql
dim rs
sql="select * from learning order by articleid 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,方便后面使用
totalPut=rs.recordcount
'当前页不能小于1,如果小于1就默认为第一页
if currentpage<1 then
currentpage=1
end if
'以下是我最不明白的地方,该程序表示当前页的记录数大于数据库记录时,(currentpage-1)*MaxPerPage>totalput怎么可能成立呢?
'假设现在目前所在的当前页是第2页,那么(2-1)*20>totalput是不可能成立,因为此时rs.recordcount至少是21条,对吧~!
if (currentpage-1)*MaxPerPage>totalput then '------问题1 所在
'如果总记录正好是20条记录的倍数时,整初后得到的就是当前页码,否则当前页码加1
if (totalPut mod MaxPerPage)=0 then
currentpage= totalPut \ MaxPerPage
else
currentpage= totalPut \ MaxPerPage + 1
end if
end if
if currentPage=1 then
'调用分页程序
call showpages
'调用信息显示表格
call showContent
'调用分页程序
call showpages
'如果当前页不是1
else
'如果当前页小于数据库记录时就显示这一页
if (currentPage-1)*MaxPerPage<totalPut then
rs.move (currentPage-1)*MaxPerPage
dim bookmark
bookmark=rs.bookmark '----------bookmark是什么意思????
call showpages
call showContent
call showpages
'如果当前信息页记录数大于数据库记录时,默认到第一页
else
currentPage=1
call showpages
call showContent
call showpages
end if
end if
rs.close
end if
set rs=nothing
conn.close
set conn=nothing
%> |
|
第1楼
|     发布时间:2006-1-2 15:17:59  点击:次 |
作者:凉风
发表: 195篇
回复: 737篇
QQ: 84207336
|     re:麻烦老师帮解析一下该分页程序 以下是显示表格信息过程
<%
'显示表格信息过程
sub showContent
dim i
i=0
%>
<table border="1" cellspacing="0" width="90%" bgcolor="#F0F8FF" bordercolorlight="#000000"
bordercolordark="#FFFFFF" align="center">
<tr>
<td width="12%" align="center">ID号</td>
<td width="13%" align="center">类型</td>
<td width="47%" align="center">信息名称</td>
</tr>
<%do while not rs.eof%>
<tr>
<td width="12%" height="7"><%=rs("articleid")%></td>
<td width="13%" height="7"><%=rs("type")%></td>
<td width="47%" height="7"><a href="viewarticle.asp?id=<%=rs("articleid")%>"><%=rs("title")%></a></td>
</tr>
<%
i=i+1
if i>=MaxPerPage then exit do
rs.movenext
loop
%>
</table>
<% end sub %>
|
|
第2楼
|     发布时间:2006-1-2 15:22:10  点击:次 |
作者:凉风
发表: 195篇
回复: 737篇
QQ: 84207336
|     re:麻烦老师帮解析一下该分页程序 以下的是分页程序
<%
sub showpages()
dim n
if (totalPut mod MaxPerPage)=0 then
n= totalPut \ MaxPerPage
else
n= totalPut \ MaxPerPage + 1
end if
if n=1 then
response.write "<p align='left'><a href=add.asp>添加信息</a>"
response.write "</p>"
exit sub
end if
dim k
response.write "<p align='left'>>> 信息分页 "
for k=1 to n
if k=currentPage then
response.write "[<b>"+Cstr(k)+"</b>] "
else
response.write "[<b>"+"<a href='manage.asp?page="+cstr(k)+"'>"+Cstr(k)+"</a></b>] "
end if
next
response.write " <a href=add.asp>创建信息</a>"
response.write "</p>"
end sub
%> |
|
第3楼
|     发布时间:2006-1-2 21:05:30  点击:次 |
作者:jjshang
发表: 211篇
回复: 14973篇
QQ:
|     re:麻烦老师帮解析一下该分页程序 问题1:您看这一段:
if (currentpage-1)*MaxPerPage>totalput then '------问题1 所在
'如果总记录正好是20条记录的倍数时,整初后得到的就是当前页码,否则当前页码加1
if (totalPut mod MaxPerPage)=0 then
currentpage= totalPut \ MaxPerPage
else
currentpage= totalPut \ MaxPerPage + 1
end if
end if
实际上,她的意思就是,如果这个条件成立了,肯定currentpage有问题,所以要重新计算了。
问题2:
Bookmark属性用来设置或返回Recordset对象的每一条记录的书签,返回值是一个字符串。每一条记录都有自己唯一的书签,它与记录在记录集中的顺序无关。将Bookmark属性存放到变量中,后面可以通过将该变量赋值给Bookmark属性,并返回到这个记录。
不过,我看这个程序中好像没有用到Bookmark,只是保存到变量中了,后来没有调用啊。
|
|
第4楼
|     发布时间:2006-1-3 17:34:28  点击:次 |
作者:凉风
发表: 195篇
回复: 737篇
QQ: 84207336
|     re:麻烦老师帮解析一下该分页程序 自我感觉这程序很麻烦~也难理解!也不知道为什么很多人都喜欢这样写~!我下载回来的原代码,到喜欢这样写分页程序,难道这样更好吗??老师你教给我们发分页程序好象还更好,更简单~只要几句就分页了
但问题1中如果这个条件成立了,肯定currentpage有问题,所以要重新计算了,真不知道什么情况下才会令到currentpage有问题,程序就是这样,如果没有实际情况,真的难以理解他的作用~
|
|
第5楼
|     发布时间:2006-1-3 17:38:46  点击:次 |
作者:凉风
发表: 195篇
回复: 737篇
QQ: 84207336
|     re:麻烦老师帮解析一下该分页程序 有时候挺怕看网上的源代码,会使人有一种混乱感~呵呵~
老师能否就这个问题1给出一个例子,说明一下发生问题的情况 |
|
第6楼
|     发布时间:2006-1-4 13:16:13  点击:次 |
作者:jjshang
发表: 211篇
回复: 14973篇
QQ:
|     re:麻烦老师帮解析一下该分页程序 作者可能过滤了,比如用户输入了一个很大的数字,或者用户自己修改传递参数,给了一个不对的页面。 |
|
第7楼
|     发布时间:2006-1-4 13:20:18  点击:次 |
作者:jjshang
发表: 211篇
回复: 14973篇
QQ:
|     re:麻烦老师帮解析一下该分页程序 作者可能考虑的太多,比如用户输入了一个很大的数字,或者用户自己修改传递参数,给了一个不对的页面。
|