主题:[讨论]数据库分页语句+循环语句不知如何融合在一起
我的分页代码是这样的:
连接数据库
<%
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>条 "
if CurrentPage<2 then
response.write"<font FONT-SIZE: 9pt>首页 上一页</font> "
else
response.write"<a href="&filename&"?page=1&>首页</a> "
response.write"<a href="&filename&"?page="&CurrentPage-1&">上一页</a> "
end if
if n-currentpage<1 then
response.write"<font FONT-SIZE: 9pt;>下一页 尾页</font>"
else
response.write"<a href="&filename&"?page="&(currentpage+1)&">下一页</a> "
response.write"<a href="&filename&"?page="&n&">尾页</a> "
end if
response.write" 页次:<strong><font color=red>"¤tpage&"</font>/"&n&"</strong>页 "
response.write"<input class=buttonface type='submit' value='转到' name='cndok' > "
response.write"第<input type='text' name='page' size=2 maxlength=3 class=smallinput value="¤tpage&">页</form>"
end function
%>
我想做一个页面是这样的:
第1页
第1条记录 第4条记录
第2条记录 第5条记录
第3条记录 第6条记录
第2页
第7条记录 第10条记录
第8条记录 第11条记录
第9条记录 第12条记录
而且我想用<%for j= 1 to 2 %>... <% next %>语句来完成,我测试了好长时间都不行,请高手帮忙指导一下,最好详细点,我是外行
连接数据库
<%
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>条 "
if CurrentPage<2 then
response.write"<font FONT-SIZE: 9pt>首页 上一页</font> "
else
response.write"<a href="&filename&"?page=1&>首页</a> "
response.write"<a href="&filename&"?page="&CurrentPage-1&">上一页</a> "
end if
if n-currentpage<1 then
response.write"<font FONT-SIZE: 9pt;>下一页 尾页</font>"
else
response.write"<a href="&filename&"?page="&(currentpage+1)&">下一页</a> "
response.write"<a href="&filename&"?page="&n&">尾页</a> "
end if
response.write" 页次:<strong><font color=red>"¤tpage&"</font>/"&n&"</strong>页 "
response.write"<input class=buttonface type='submit' value='转到' name='cndok' > "
response.write"第<input type='text' name='page' size=2 maxlength=3 class=smallinput value="¤tpage&">页</form>"
end function
%>
我想做一个页面是这样的:
第1页
第1条记录 第4条记录
第2条记录 第5条记录
第3条记录 第6条记录
第2页
第7条记录 第10条记录
第8条记录 第11条记录
第9条记录 第12条记录
而且我想用<%for j= 1 to 2 %>... <% next %>语句来完成,我测试了好长时间都不行,请高手帮忙指导一下,最好详细点,我是外行