读书人

ASP分页代码出错找了很久找不出来

发布时间: 2012-06-19 14:45:20 作者: rapoo

ASP分页代码出错,找了很久找不出来,麻烦有空帮我看一下。
<%
sub WebContent(DataFrom,ID,SortPath)
'-------------------
dim rs,sql
dim HideSort '未对外发布的类别
set rs = server.createobject("adodb.recordset")
'根据当前类别ID取需要列表产品的类别路径SortPath开始
if ID="" then
SortPath="0,"
elseif not IsNumeric(ID) then%>
<div class="Bodyer_right_page_content">暂无相关信息</div>
<%exit sub
elseif conn.execute("select * from "&DataFrom&" Where ID="&ID).eof then%>
<div class="Bodyer_right_page_content">暂无相关信息</div>
<%exit sub
else
SortPath=conn.execute("select * from "&DataFrom&" Where ID="&ID)("SortPath")
conn.execute("update "&DataFrom&" set ClickNumber=ClickNumber+1 Where ID="&ID)
end if
sql="select * from "&DataFrom&" Where 1<>1 and Instr(SortPath,'"&SortPath&"')>0"
'根据当前类别ID取需要列表产品的类别路径SortPath结束
rs.open sql,conn,1,1
while not rs.eof
HideSort="and not(Instr(SortPath,'"&rs("SortPath")&"')>0) "&HideSort
rs.movenext
wend
rs.close
'-------------------
dim idCount'记录总数
dim pages'每页条数
pages=16
dim pagec'总页数
dim page'页码
page=clng(request("Page"))
dim pagenc'每页显示的分页页码数量=pagenc*5+1
pagenc=5
dim pagenmax'每页显示的分页的最大页码
dim pagenmin'每页显示的分页的最小页码
dim pageprevious'上一相邻的页码
dim pagenext '下一相邻的页码
'重置数据表名
datafrom="evset_Products"
dim datawhere'数据条件
datawhere="where Instr(SortPath,'"&SortPath&"')>0 "&HideSort& " "
dim sqlid'本页需要用到的id
dim Myself,PATH_INFO,QUERY_STRING'本页地址和参数
PATH_INFO = request.servervariables("PATH_INFO")
QUERY_STRING = request.ServerVariables("QUERY_STRING")'
if QUERY_STRING = "" then
Myself = PATH_INFO & "?"
elseif Instr(PATH_INFO & "?" & QUERY_STRING,"Page=")=0 then
Myself= PATH_INFO & "?" & QUERY_STRING & "&"
else
Myself = Left(PATH_INFO & "?" & QUERY_STRING,Instr(PATH_INFO & "?" & QUERY_STRING,"Page=")-1)
end if
dim taxis'排序的语句 asc,desc
taxis="order by Sequence asc "
dim i'用于循环的整数
'获取记录总数
'sql="select * from evset_Products where Instr(SortPath,'"&SortPath&"')>0 "&HideSort
sql="select count(ID) as idCount from ["& datafrom &"]" & datawhere
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,0,1
idCount=rs("idCount")
'获取记录总数
if(idcount>0) then'如果记录总数=0,则不处理
if(idcount mod pages=0)then'如果记录总数除以每页条数有余数,则=记录总数/每页条数+1
pagec=int(idcount/pages)'获取总页数
else
pagec=int(idcount/pages)+1'获取总页数
end if
'获取本页需要用到的id============================================
'读取所有记录的id数值,因为只有id所以速度很快
sql="select id from ["& datafrom &"] " & datawhere & taxis
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
rs.pagesize = pages '每页显示记录数
if page < 1 then page = 1
if page > pagec then page = pagec
if pagec > 0 then rs.absolutepage = page


for i=1 to rs.pagesize
if rs.eof then exit for
if(i=1)then
sqlid=rs("id")
else
sqlid=sqlid &","&rs("id")
end if
rs.movenext
next
'获取本页需要用到的id结束============================================
end if
if(idcount>0 and sqlid<>"") then'如果记录总数=0,则不处理
'用in刷选本页所语言的数据,仅读取本页所需的数据,所以速度快
sql="select * from ["& datafrom &"] where id in("& sqlid &") "&taxis
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,0,1
dim tr,td'定义行数与列数
dim ProductName,SmallPicPath,Content%>
<%for tr=1 to 3%>
<% for td=1 to 6 '填充数据到表格
if StrLen(rs("ProductName"&Language))<=18 then
ProductName=rs("ProductName"&Language)
else
ProductName=StrLeft(rs("ProductName"&Language),16)
end if
SmallPicPath=HtmlSmallPic(rs("GroupID"),rs("SmallPic"),rs("Exclusive"))%>
<ul class="productul">
<li class="cproductspic"><a href="productview.asp?ID=<%= rs("id") %>"><img src="<%= replace(SmallPicPath,"../","") %>" <%if instr(SmallPicPath,"s_")=0 then%>onload="javascript:DrawImage(this,61,75);"<%end if%> alt="<%= rs("ProductName"&Language) %>" border="0" /></a></li>
<li class="cproductstitle"><a href="productview.asp?ID=<%= rs("id") %>" title="<%= rs("ProductName"&Language) %>"><%= ProductName %></a></li>
</ul>
<% rs.movenext
if rs.eof then exit for
next%>

<%if rs.eof then exit for
next%>
<div class="clear"></div>
<% else%>
<div class="noxinwei">
<p>暂无相关图片……! <a href="javascript:history.back(-1)">返回上一页</a></p></div>
<%exit sub
end if%>
<div class="digg">
<%if language="Ch" then%>
共计:<font color="#ff6600"><%= idcount %></font>条记录  页次:<font color="#ff6600"><%= page %></font></strong>/<%= pagec %>  每页:<font color="#ff6600"><%= pages %></font>条


<%end if%>
<% pagenmin=page-pagenc '计算页码开始值
pagenmax=page+pagenc '计算页码结束值
if(pagenmin<1) then pagenmin=1 '如果页码开始值小于1则=1%>
<% if(page>1) then %>
<a href="<%= myself %>Page=1" title="跳到第1页">第一页</a>
<%end if
if page-(pagenc*2+1)<=0 then
pageprevious=1
else
pageprevious=page-(pagenc*2+1)
end if
if(pagenmin>1) then%>
<a href="<%= myself %>Page=<%= pageprevious %>" title="第<%= pageprevious %>页">上一页</a>

<%end if

if page+(pagenc*2+1)>=pagec then
pagenext=pagec
else
pagenext=page+(pagenc*2+1)
end if
if(pagenmax<pagec) then %>
<a href="<%= myself %>Page=<%= pagenext %>" title="跳到第<%= pagenext %>页">下一页</a> 
<% end if
if(page<pagec) then %>
 <a href="<%= myself %>Page=<%= pagec %>" title="跳到第<%= pagec %>">最后一页</a>


<%end if%>
</div>
<%
rs.close
set rs=nothing
end sub
%>
能显示分页,但是好像第一页跟上一页代码效果都是跳转到第一页,下一页和最后一页都是跳转到最后一页。麻烦了。。。

[解决办法]
<%
sub showpagebar(totalpage,curpage,strurl)
dim strpage
crupage=getvalidpageno(totalpage,curpage)
if curpage="" then
curpage=0
end if
if totalpage="" then
totalpage=0
end if
response.write "第<font color=red>"&curpage&"</font>页 / 共<font color=red>"&totalpage&"</font>页 "
if instr(strurl,"?")=0 then
strpage="?page="
else
strpage="&page="
end if
if curpage>1 then
response.write "  [  <a href="&strurl&strpage&"1>首页</a>  |"
else
response.write "  [  首页  |"
end if
if curpage>=2 then
response.write "  <a href="&strurl&strpage&curpage-1&">上一页</a>  |"
else
response.write "  上一页  |"
end if
if cint(curpage)<cint(totalpage) then
response.write "  <a href="&strurl&strpage&curpage+1&">下一页</a>  |"
else
response.write "  下一页  |"
end if
if cint(curpage)<>cint(totalpage) then
response.write "  <a href="&strurl&strpage&totalpage&">尾页</a>  ]"
else
response.write "  尾页  ]"
end if
end sub
function getvalidpageno(pagecount,curpage)
dim ipage
ipage=curpage
if cint(curpage)<1 then
ipage=1
end if
if cint(ipage)>cint(pagecount) then
ipage=pagecount
end if
getvalidpageno=ipage
end function
%>
分页用得了写这么多嘛~真是~给

读书人网 >ASP

热点推荐