注册 登录
编程论坛 ASP技术论坛

asp 复杂表格的分页问题

yuchangyu 发布于 2010-05-12 23:54, 676 次点击
一个复杂的嵌套表格,现在要分页,每页显示6条数据,数据已经正确读取,可是分页的时候第二页也是显示的第一页的数据,请高手帮忙~~
<%dim bc,jh,ssjj
'response.Write(request.form("sj"))&"\\\\\\\\"
ssjj=request("WS_Officesj")

Set rs0 = Server.CreateObject("ADODB.Recordset")
                 sql="select * from cyrbb where WS_Officesj='"&ssjj&"' order by id asc"
                  rs0.open sql,Conn,3,3

'response.Write(rs("jh"))
'rs.movenext
'response.Write(rs("jh"))              
if rs0.bof and rs0.eof then
'response.Write(rs("sj"))&sql
%>
<script language="javascript">
alert("对不起数据库中没有您要生成报表的记录,请选择正确的时间或及时将数据入库之后再生成!")
window.history.go(-1)
</script>
<%else
Set rs = Server.CreateObject("ADODB.Recordset")
 sql= "Select * From cyrbb Where ID In (Select Max(ID) From cyrbb Group By jh) and WS_Officesj='"&request("WS_Officesj")&"' order by id asc"
  rs.open sql,Conn,3,3
  rs.movefirst
jh=rs("jh")
<table border="1" cellpadding="0" cellspacing="0">
  <tr height="20">
    <td rowspan="5" align="center" height="98" width="72"><p class="STYLE7"><strong>井</strong></p>
    <p class="STYLE7"><strong>号</strong></p></td>
    <td rowspan="5" align="center" width="72"><p class="STYLE7"><strong>泵径</strong></p>
    <p class="STYLE7"><strong>泵深</strong></p>
    <p class="STYLE7"><strong>mm/m</strong></p></td>
    <td rowspan="5" align="center" width="72"><p class="STYLE7"><strong>冲程</strong></p>
    <p class="STYLE7"><strong>冲次</strong></p>
    <p class="STYLE7"><strong>m/次</strong></p></td>
    <td colspan="6" align="center" width="432"><span class="STYLE7"><strong>生产动态情况反应</strong></span></td>
    <td colspan="6" align="center" width="432"><span class="STYLE7"><strong>流 量 计 求 产 记 录</strong></span></td>
    <td rowspan="5" align="center" width="72"><span class="STYLE7"><strong>备 注</strong></span></td>
  </tr>
  <tr height="19">
    <td rowspan="4" align="center" height="78" width="72"><p class="STYLE7"><strong>生产</strong></p>
    <p class="STYLE7"><strong>时间</strong></p>
    <p class="STYLE7"><strong>hmin</strong></p></td>
    <td rowspan="4" align="center" width="72"><p class="STYLE7"><strong>观察</strong></p>
    <p class="STYLE7"><strong>时间</strong></p>
    <p class="STYLE7"><strong>hmin</strong></p></td>
    <td rowspan="4" align="center" width="72"><p class="STYLE7"><strong>油压</strong></p>
    <p class="STYLE7"><strong>MPa</strong></p></td>
    <td rowspan="4" align="center" width="72"><p class="STYLE7"><strong>套压</strong></p>
    <p class="STYLE7"><strong>MPa</strong></p></td>
    <td rowspan="4" align="center" width="72"><p class="STYLE7"><strong>回压</strong></p>
    <p class="STYLE7"><strong>MPa</strong></p></td>
    <td rowspan="4" align="center" width="72"><span class="STYLE7"><strong>生产情况</strong></span></td>
    <td colspan="2" align="center" rowspan="2" width="144"><span class="STYLE7"><strong>求 产 起 始</strong></span></td>
    <td colspan="2" align="center" rowspan="2" width="144"><span class="STYLE7"><strong>求 产 结 束</strong></span></td>
    <td rowspan="4" align="center" width="72"><p class="STYLE7"><strong>时间</strong></p>
    <p class="STYLE7"><strong>差值</strong></p>
    <p class="STYLE7"><strong>hmin</strong></p></td>
    <td rowspan="4" align="center" width="72"><p class="STYLE7"><strong>液 量</strong></p>
    <p class="STYLE7"><strong><strong>差值</strong></strong></p>
    <p class="STYLE7"><strong><strong><strong>m<sup>3</sup></strong></strong></strong></p></td>
  </tr>
  <tr height="20"> </tr>
  <tr height="19">
    <td rowspan="2" align="center" height="39" width="72"><span class="STYLE7"><strong>时间</strong></span></td>
    <td rowspan="2" align="center" width="72"><p class="STYLE7"><strong>液量</strong></p>
    <p class="STYLE7"><strong>读数</strong></p></td>
    <td rowspan="2" align="center" width="72"><span class="STYLE7"><strong>时 间</strong></span></td>
    <td rowspan="2" align="center" width="72"><p class="STYLE7"><strong>液量</strong></p>
    <p class="STYLE7"><strong><strong>读数</strong></strong></p></td>
  </tr>
  <tr height="20"> </tr>
<%
dim WS_Officebjbs,WS_Officecccc,WS_Officescsj,m,n
Set rsi = Server.CreateObject("ADODB.Recordset")
sql1="SELECT DISTINCT jh FROM cyrbb where WS_Officesj='"&ssjj&"'"
rsi.open sql1,Conn,3,3
'response.Write(rsi.recordcount)
'response.Write(rsi("jh"))&"\\\\\"
rsi.pagesize=6            '定义一页显示的记录数目
tatalrecord=rsi.recordcount  '获取记录总数目
tatalpages=rsi.pagecount     '获取分页的数目
rsi.movefirst

nowpage=request("page")   '用request获取当前页数,注意page是自己定义的变量并非函数

if nowpage&"x"="x" then   '处理页码为空时的情况??怎么没事。我传给你吧我没asp
nowpage=1
else
nowpage=cint(nowpage)   '将页码转换成数字型
end if

rsi.absolutepage=nowpage    '将指针移动到当前显示页的第一条记录
n=1

for i= 1 to rsi.pagesize

if i<rsi.recordcount then
3 回复
#2
gupiao1752010-05-13 11:37
怎么到这里if i<rsi.recordcount then 就结束了?
#3
shcnlm2010-05-13 18:20
好像没看到你设置page的大小.
我写段代码你参考下吧.
程序代码:
<%
conn
="DBQ="&server.MapPath("mydb.mdb")&";defaultdir=;Driver={Microsoft Access Driver (*.mdb)};"
sql
="select * from user"
set rs=server.CreateObject("ADODB.recordset")
rs.open sql,conn,
1,1
const maxsize=5'设置页面的记录数的大小,用CONST声明不可修改变量
rs.pagesize=maxsize'这个很关键,要记得设置好记录数后,最好设置下页面的大小,即每页显示的数据数量.
rs.moveFirst'设置完成后记得将记录指针移到第一条记录,虽然有时不移也可以,但可能会出错.
allfields=rs.fields.count-1
allpage
=rs.pagecount
if trim(request("page"))<>"" then'这段是判断返回的PAGE参数,注意trim和clng二个函数的使用,不能少.否则可能会出错.
nowpage=clng(request("page"))
if nowpage>allpage then
nowpage
=allpage
end if
else
nowpage
=1
end if
if rs.eof then'这段是分页显示的关键,首页判断数据库有没有数据,再将鼠标指针移到相应的数据记录上.
response.Write("数据库中没有数据")
else
allfiles
=rs.recordcount
if nowpage<>1 then
if (nowpage-1)*maxsize<allfiles then
rs.move((nowpage
-1)*maxsize)
end if
end if
%>
<table align="center" bgcolor="#eeeeee"><tr><td colspan="<%=rs.fields.count%>" bgcolor="#CCCCCC" align="center">数据库数据表</td></tr>
<tr><% for i=0 to allfields %><td bgcolor="#CCCCCC" width="100" align="center"><%=rs(i).name%></td><%next%></tr>
<%
h
=0
do while not rs.eof and h<maxsize%>
<tr><%for i=0 to allfields %><td><%=rs(i).value%></td><%next%></tr><%h=h+1
rs.movenext
loop%>
<tr><td colspan="<%=rs.fields.count%>" bgcolor="#CCCCCC" align="center">
<%
if nowpage=1 then
response.Write(
"首页  上一页")
else%><a href="test8.asp?page=1">首页</a>  <a href="test8.asp?page=<%=cstr(nowpage-1)%>">上一页</a>
<%end if
if nowpage=allpage then
response.Write(
"下一页  尾页")
else%><a href="test8.asp?page=<%=cstr(nowpage+1)%>">下一页</a>  <a href="test8.asp?page=<%=allpage%>">尾页</a>
<%end if%>

</td></tr>
</table>
<%
with response
.Write(
trim(request("page")))
.write(
clng(request("page")))
.write(allpage)
.write(nowpage)
end with
end if
rs.close
set rs=nothing
%>

希望能帮到你.
#4
yms1232010-05-13 18:58
检查参数传递问题,分页控制(也就是上一页,下一页代码)哪里怎么写的?还有分页查询数据库的参数获取代码没有看到怎么写的?
1