回 帖 发 新 帖 刷新版面

主题:[讨论]数据库分页语句+循环语句不知如何融合在一起

我的分页代码是这样的:
连接数据库
<% 
sql="select * from 1157  order by id "
rs.Open sql,conn,1,1
if rs.eof and rs.bof then
response.write"<p align='center'>还没有任何信息</p>"
else
totalPut=rs.recordcount
totalPut=rs.recordcount
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
if currentPage=1 then
showContent
showpage totalput,MaxPerPage,"117.asp"
else
if(currentPage-1)*MaxPerPage<totalPut then
rs.move (currentPage-1)*MaxPerPage
dim bookmark
bookmark=rs.bookmark
showContent
showpage totalput,MaxPerPage,"117.asp"
else
currentPage=1 
showContent
showpage totalput,MaxPerPage,"117.asp"
end if
end if
rs.close
end if
set rs=nothing
conn.close
set conn=nothing
sub showContent
dim i
i=0
%>

<table width="299" border="0" cellpadding="0" cellspacing="0">
<% do while not rs.eof %> 
          <tr>                         
            <td><%=rs("name")%></td>
           </tr>
<% i=i+1
  if i>=MaxPerPage then exit do
  rs.movenext
  loop
  %>
</table>

<%
end sub
function showpage(totalnumber,maxperpage,filename)
dim n
if totalnumber mod maxperpage=0 then
n=totalnumber\maxperpage
else
n=totalnumber\maxperpage+1
end if
response.write"<form method=post action="&filename&">"
response.write"共<strong><font color='red'>"&totalnumber*2&"</font></strong>条&nbsp;&nbsp;"
if CurrentPage<2 then
response.write"<font FONT-SIZE: 9pt>首页 上一页</font>&nbsp;"
else
response.write"<a href="&filename&"?page=1&>首页</a>&nbsp;&nbsp;"
response.write"<a href="&filename&"?page="&CurrentPage-1&">上一页</a>&nbsp;&nbsp;"
end if
if n-currentpage<1 then
response.write"<font FONT-SIZE: 9pt;>下一页 尾页</font>"
else
response.write"<a href="&filename&"?page="&(currentpage+1)&">下一页</a>&nbsp;&nbsp;"
response.write"<a href="&filename&"?page="&n&">尾页</a>&nbsp;&nbsp;"
end if
response.write"&nbsp;页次:<strong><font color=red>"&currentpage&"</font>/"&n&"</strong>页&nbsp;&nbsp;&nbsp;&nbsp;"
response.write"<input class=buttonface type='submit' value='转到' name='cndok' >&nbsp;&nbsp;"
response.write"第<input type='text' name='page' size=2 maxlength=3 class=smallinput value="&currentpage&">页</form>"
end function
%>


我想做一个页面是这样的:
第1页
第1条记录   第4条记录
第2条记录   第5条记录
第3条记录   第6条记录

第2页
第7条记录   第10条记录
第8条记录   第11条记录
第9条记录   第12条记录

而且我想用<%for j= 1 to 2 %>...  <% next %>语句来完成,我测试了好长时间都不行,请高手帮忙指导一下,最好详细点,我是外行


回复列表 (共2个回复)

沙发

<TABLE border=0>
<TR>
<%
For i=1 To 6
If i Mod 3=1 Then
%>
<TD><TABLE border=1>
<%
End if
%>
    <TR>
        <TD>第<%=i%>条记录</TD>
    </TR>
<%
If i Mod 3=0 Then
%>
    </TABLE></TD>
<%
End If
next 
%>
</TR>
</TABLE>

板凳


非常感谢楼上的,按您上面代码效果是这样的:
第1页
第1条记录   第1条记录
第1条记录   第1条记录
第1条记录   第1条记录

第2页
第2条记录   第2条记录
第2条记录   第2条记录
第2条记录   第2条记录


我想应该还要加入两句:

<% do while not rs.eof %>

<% i=i+1
  if i>=MaxPerPage then exit do
  rs.movenext
  loop
  %>

但位置不知道放在哪儿,测试总不能达到一楼效果

我来回复

您尚未登录,请登录后再回复。点此登录或注册