主题:[讨论]我想把数据库表格里的记录按以下方式排列
zhqmpc001
[专家分:0] 发布于 2007-01-03 19:51:00
我想把数据库表格里的记录按以下方式排列,不只是否能实现,如果可以代码应该怎么写,请大家帮忙
第一页
第1条记录 第6条记录
第2条记录 第7条记录
第3条记录 第8条记录
第4条记录 第9条记录
第5条记录 第10条记录
第二页
第11条记录 第16条记录
第12条记录 第17条记录
第13条记录 第18条记录
第14条记录 第19条记录
第15条记录 第20条记录
回复列表 (共7个回复)
沙发
longlong16 [专家分:10670] 发布于 2007-01-04 09:36:00
即每页显示10条记录而已
用两重循环:
<%for i=1 to 2%>
<table width=50%>
<%for j = 1 to 5 %>
<tr><td>..</td></tr>
<% next %>
</table>
<% next %>
分页部分和正常分页代码相同
板凳
zhqmpc001 [专家分:0] 发布于 2007-01-04 16:44:00
谢谢longlong16,按您的方法做出来如下:
第一页
第1条记录 第1条记录
第1条记录 第1条记录
第1条记录 第1条记录
第1条记录 第1条记录
第1条记录 第1条记录
第二页
第11条记录 第11条记录
第11条记录 第11条记录
第11条记录 第11条记录
第11条记录 第11条记录
第11条记录 第11条记录
还应该怎么改才能达到1楼的那种排列
3 楼
wcc9 [专家分:130] 发布于 2007-01-04 22:08:00
你是想从数据库里读出记录吗??如果是你就用这个:
If Not rs.Bof And Not rs.Eof Then
'以下主要为了分页显示
rs.PageSize=10 '设置每页显示10条记录
dim page_total '定义总页数变量
page_total=rs.PageCount '返回总页数,会在下面输出数据页时用到
rs.AbsolutePage=page_no '设置当前显示第几页,这里用到了传过来的page_no。
'下面一段利用表格显示当前页的所有记录
Dim gg,Jc
gg=rs.PageSize '变量I用来控制显示当前页记录,注意这里和rs.PageSize要一致。
Jc=0 '变量J用来控制每行显示3条记录
Response.Write "<tr>" '可以在这里输出开始新行的标记
Do While Not rs.Eof And gg>0 '循环直到当前页结束或文件结尾
gg=gg-1 '每显示一条,I减1,当变成0时,表示本页结束
Jc=Jc+1
%>
<td width="157" height="100" align='center' valign="top" class="STYLE5">
<a href='uploadpic/<%=rs("image")%>' target='_blank'><img src="../shupic/<%=rs("image")%>"border="0" width="135" height="160" onload="javascript:DrawImage(this);" ></a>
<span class="STYLE1"><a href="" target="_blank">
<p><%=rs("shuname")%></a></span> <p class="STYLE5">潮流价:<%=rs("cprice")%> 元 </td>
<%If (Jc mod 2)=0 Then
Response.Write "</tr><tr>"
End If
rs.MoveNext
Loop
End if
%>
4 楼
wcc9 [专家分:130] 发布于 2007-01-04 22:09:00
变量gg用来控制显示当前页记录
5 楼
zhqmpc001 [专家分:0] 发布于 2007-01-04 23:38:00
我的代码是这样的,显示也都正常了,但在最后一页出现这样的错误,应该怎么改
出现错误:ADODB.Field 错误 '80020009'
BOF 或 EOF 中有一个是“真”,或者当前的记录已被删除,所需的操作要求一个当前的记录。
代码如下:
<%
const MaxPerPage=12
dim totalPut
dim CurrentPage
dim TotalPage
dim i,j
if not isempty(request("page"))then
currentpage=cint(request("page"))
else
currentpage=1
end if
%>
<!--#include file="1.asp" --> '连接数据库
<%
sql="select * from hk where name ='tt' 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,"55.asp"
else
if(currentPage-1)*MaxPerPage<totalPut then
rs.move (currentPage-1)*MaxPerPage
dim bookmark
bookmark=rs.bookmark
showContent
showpage totalput,MaxPerPage,"55.asp"
else
currentPage=1
showContent
showpage totalput,MaxPerPage,"55.asp"
end if
end if
rs.close
end if
set rs=nothing
conn.close
set conn=nothing
sub showContent
dim i
i=0
dim j
j=0
%>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr><%for i=1 to 2%>
<td valign="top"><table border="0" cellpadding="0" cellspacing="0">
<%for j = 1 to 6 %>
</tr>
<td width="23" height="25"><%= rs("id")%></td>
</tr>
<%
rs.movenext
next
%>
</table>
</td><% next %>
</tr>
</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*3&"</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
%>
6 楼
wcc9 [专家分:130] 发布于 2007-01-05 21:16:00
把这个totalnumber\maxperpage+1
改成int(totalnumber\maxperpage)+1试一下..
7 楼
zhqmpc001 [专家分:0] 发布于 2007-01-05 22:04:00
谢谢wcc9
还是这个错误
出现错误:ADODB.Field 错误 '80020009'
BOF 或 EOF 中有一个是“真”,或者当前的记录已被删除,所需的操作要求一个当前的记录。
我来回复