心灵终结黑屏:为什么用ASP分页时会这样出错?
数据库里已经有了6个图片,本来应该是有3页,每页两个的.
但不知为什么,以下代码出来的却是这样的情况:
第一页显示6个图片,每二页显示4个图片,第三页显示2个图片,依次递减.
=以下是代码=
<% set rs=server.createobject("adodb.recordset")
sqltext="select * from view order by dat desc"
rs.open sqltext,conn,1,1
if rs.recordcount=0 then
%><table width="100%" border="0" cellspacing="0" cellpadding="5" align="center"> <tr><td align=center>对不起,暂时还没有任何内容!</td></tr></table>
<%else
rs.PageSize =2 '每页记录条数
iCount=rs.RecordCount '记录总数
iPageSize=rs.PageSize
maxpage=rs.PageCount
page=request("page")
if Not IsNumeric(page) or page="" then
page=1
else page=cint(page)
end if
if page<1 then
page=1
elseif page>maxpage then
page=maxpage
end if
rs.AbsolutePage=Page
if page=maxpage then
x=iCount-(maxpage-1)*iPageSize
else x=iPageSize
end if
%>
<table width="100%" border="1" cellpadding="3" cellspacing="2" bordercolor="#CCCCCC" bgcolor="#FFFFFF">
<% For i=1 To x %>
<% t=1
do while not rs.eof %>
<td width="32%" height="191" align="center" valign="middle"><div align="center">
<img src="<%= rs("pic") %>" width="242" height="180" border="0"></div></td>
<%if (t mod 2)=0 then response.write "<tr>" '两列显示mod 2
t=t+1
rs.movenext
loop
%>
</tr>
<% next %>
</table>
<% call PageControl(iCount,maxpage,page,"border=0 align=center","<p align=center>")
end if
rs.close
set rs=nothing
Sub PageControl(iCount,pagecount,page,table_style,font_style)
Dim query, a, x, temp
action = "http://" & Request.ServerVariables("HTTP_HOST") & Request.ServerVariables("SCRIPT_NAME")
query = Split(Request.ServerVariables("QUERY_STRING"), "&")
For Each x In query
a = Split(x, "=")
If StrComp(a(0), "page", vbTextCompare) <> 0 Then
temp = temp & a(0) & "=" & a(1) & "&"
End If
Next
Response.Write("<table " & Table_style & ">" & vbCrLf )
Response.Write("<form method=get onsubmit=""document.location = '" & action & "?" & temp & "Page='+ this.page.value;return false;""><TR>" & vbCrLf )
Response.Write("<TD align=right>" & vbCrLf )
Response.Write(font_style & vbCrLf )
if page<=1 then
Response.Write ("首页 " & vbCrLf)
Response.Write ("上一页 " & vbCrLf)
else
-------------------------由于字数限制,这里的部分分页代码缩略----------------
End Sub
%>
For i=1 To x
不要用x 用rs.pagesize
========================================
照这样改了,不过效果还是一样,没有任何变化.
For i=1 To x
不要用x 用rs.pagesize
do while not rs.eof %>
<td width="32%" height="191" align="center" valign="middle"><div align="center">
<img src="<%= rs("pic") %>" width="242" height="180" border="0"></div></td>
<%if (t mod 2)=0 then response.write "<tr>" '两列显示mod 2
t=t+1
rs.movenext
loop
这里不再用循环 有那个for next循环就可以了
我想用ASP来分页,每页显示两个图片.
数据库里已经有了6个图片,本来应该是有3页,每页两个的.
但不知为什么,以下代码出来的却是这样的情况:
第一页显示6个图片,每二页显示4个图片,第三页显示2个图片,依次递减.
=以下是代码=
<% set rs=server.createobject("adodb.recordset")
sqltext="select * from view order by dat desc"
rs.open sqltext,conn,1,1
if rs.recordcount=0 then
%><table width="100%" border="0" cellspacing="0" cellpadding="5" align="center"> <tr><td align=center>对不起,暂时还没有任何内容!</td></tr></table>
<%else
rs.PageSize =2 '每页记录条数
iCount=rs.RecordCount '记录总数
iPageSize=rs.PageSize
maxpage=rs.PageCount
page=request("page")
if Not IsNumeric(page) or page="" then
page=1
else page=cint(page)
end if
if page<1 then
page=1
elseif page>maxpage then
page=maxpage
end if
rs.AbsolutePage=Page
if page=maxpage then
x=iCount-(maxpage-1)*iPageSize
else x=iPageSize
end if
%>
<table width="100%" border="1" cellpadding="3" cellspacing="2" bordercolor="#CCCCCC" bgcolor="#FFFFFF">
<% For i=1 To x %>
<% t=1
do while not rs.eof %>
<td width="32%" height="191" align="center" valign="middle"><div align="center">
<img src="<%= rs("pic") %>" width="242" height="180" border="0"></div></td>
<%if (t mod 2)=0 then response.write "<tr>" '两列显示mod 2
t=t+1
rs.movenext
loop
%>
</tr>
<% next %>
</table>
<% call PageControl(iCount,maxpage,page,"border=0 align=center","<p align=center>")
end if
rs.close
set rs=nothing
Sub PageControl(iCount,pagecount,page,table_style,font_style)
Dim query, a, x, temp
action = "http://" & Request.ServerVariables("HTTP_HOST") & Request.ServerVariables("SCRIPT_NAME")
query = Split(Request.ServerVariables("QUERY_STRING"), "&")
For Each x In query
a = Split(x, "=")
If StrComp(a(0), "page", vbTextCompare) <> 0 Then
temp = temp & a(0) & "=" & a(1) & "&"
End If
Next
Response.Write("<table " & Table_style & ">" & vbCrLf )
Response.Write("<form method=get onsubmit=""document.location = '" & action & "?" & temp & "Page='+ this.page.value;return false;""><TR>" & vbCrLf )
Response.Write("<TD align=right>" & vbCrLf )
Response.Write(font_style & vbCrLf )
if page<=1 then
Response.Write ("首页 " & vbCrLf)
Response.Write ("上一页 " & vbCrLf)
else
<% set rs=server.createobject("adodb.recordset")
sqltext="select * from view order by dat desc"
rs.open sqltext,conn,1,1
if rs.recordcount=0 then
%><table width="100%" border="0" cellspacing="0" cellpadding="5" align="center"> <tr><td align=center>对不起,暂时还没有任何内容!</td></tr></table>
<%else
rs.PageSize =2 '每页记录条数
iCount=rs.RecordCount '记录总数
iPageSize=rs.PageSize
maxpage=rs.PageCount
page=request("page")
if Not IsNumeric(page) or page="" then
page=1
else page=cint(page)
end if
if page<1 then
page=1
elseif page>maxpage then
page=maxpage
end if
rs.AbsolutePage=Page
if page=maxpage then
x=iCount-(maxpage-1)*iPageSize
else x=iPageSize
end if
%>
<table width="100%" border="1" cellpadding="3" cellspacing="2" bordercolor="#CCCCCC" bgcolor="#FFFFFF">
<%t=1%>
<% For i=1 To x %>
<%
do while not rs.eof %>
<td width="32%" height="191" align="center" valign="middle"><div align="center">
<img src="<%= rs("pic") %>" width="242" height="180" border="0"></div></td>
<%if (t mod 2)=0 then response.write "<tr>" '两列显示mod 2
t=t+1
rs.movenext
loop
rs.movenext
%>
</tr>
<% next %>
</table>
试试~~~