分页老问题,不一定好解决,相信吗?

xiaojun2000 2001-05-18 05:53:00
加精
我的数据太少了,我想让其分为两列排列,且具有分页的功能。我目前只做到这一点,要不只可以分页,要不只可以分列,能否两方面结合到一起呢?
...全文
146 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaojun2000 2001-05-20
  • 打赏
  • 举报
回复
不好意思,现在马上加分
freezwy 2001-05-19
  • 打赏
  • 举报
回复
本问题已经有很多人问,所以,今天作了一个测试程序,测试成功,代码如下:
关键问题:
1.根据每页的记录数量计算出需要的表格行
2.根据HTML作出结果,其实这个问题的根本就是HTML算法显示.
源代码如下:记住给分.
---------------------
测试数据表如下:access2000
id autoincrement
vname char
vcontent char
=====================================
query.asp
<html>
<head>
<title>查询</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel=stylesheet href=../style.css>
</head>
<body bgcolor="#FFFFFF">
<p> </p>
<p> </p>
<hr align=center color=#FFE1A4 noShade size=1 >
<p> </p><table width="39%" border="1" height="1" cellspacing="0" bordercolorlight="#000000" bordercolordark="#ffffff" align="center" cellpadding="0">
<tr bgcolor="#F5F3FA" valign="top">
<td class="font9" bgcolor="#F5F3FA">
<div align="center">一般搜索</div>
</td>
</tr>
<tr >
<td class="font9" height="17">
<form name="form1" method="post" action="result.asp" >
<div align="center">姓 名 :
<input type="text" name="vname" class="smallInput" maxlength="20">
<input type="submit" style="color:#000000;BACKGROUND-COLOR:#DED1EF; FONT-SIZE: 9pt;height:22" value="搜索" name="submit1" class="buttonface" >
</div>
</form>
</td>
</tr>
</table><p> </p><hr align=center color=#FFE1A4 noShade size=1 >
<p align="center">Written by freezwy</p>
==========================================================================
result.asp
<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq="& Server.MapPath("test.mdb")
' const maxperpage=10 
maxperpage=10
'定义每页的记录数量
dim totalPut
dim CurrentPage
dim TotalPages
dim i,j
if not isempty(request("page")) then
currentPage=cint(request("page"))
else
currentPage=1
end if
'关键是这里
z=maxperpage mod 2
if z<>0 then
y=maxperpage\2+1
else
y=maxperpage/2
end if
'y是这个页面双行显示的表格的行数
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
<title>查询结果</title>
<script language="javascript">
function opennew(id)
{window.open("rcxx.asp?id="+id,"","height=500,width=570,resizable=yes,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no,left=100,top=10");
}
</script>
<link rel=stylesheet href=../style.css>
<body bgcolor="#FFFFFF">
<div align="center">
<hr align=center color=#FFE1A4 noShade size=1 >
<table border="0" cellspacing="1" width="98%" >
<tr>
<td width="100%" height="96">
<%
vname=trim(request("vname"))
sql="select * from test where instr(vname,'"&vname&"')>0 order by id desc"
Set rs= Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,1,1
if rs.eof then
response.write "<p align='center'>没有你要找的信息</p>"
else
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
showpage totalput,MaxPerPage,"result.asp",vname
showContent
showpage totalput,MaxPerPage,"result.asp",vname
else
if (currentPage-1)*MaxPerPage<totalPut then
rs.move (currentPage-1)*MaxPerPage
dim bookmark
bookmark=rs.bookmark
showpage totalput,MaxPerPage,"result.asp",vname
showContent
showpage totalput,MaxPerPage,"result.asp",vname
else
currentPage=1
showpage totalput,MaxPerPage,"result.asp",vname
showContent
showpage totalput,MaxPerPage,"result.asp",vname
end if
end if
rs.close
end if
set rs=nothing
conn.close
set conn=nothing
sub showContent
dim i
i=0
%>
<div align="center">
<table border="1" width="54%" cellspacing="0" cellpadding="1" style="font-size: 9pt" bordercolorlight="#666666" bordercolordark="#FFFFFF">
<tr>
<td width="203" bgcolor="#F5F3FA">姓名</td>
<td width="197" bgcolor="#F5F3FA">说明</td>
<td rowspan=<%=y+1%> width="150"> </td>
<%'这里加上一个空行是为了显示的方便%>
<td width="203" bgcolor="#F5F3FA">姓名</td>
<td width="197" bgcolor="#F5F3FA">说明</td>

</tr>
<tr>
<%
'关键是把<tr>标志放到外边
do while not rs.eof%>
<%if (i mod 2)=0 then%>
<td align=center width="203" height="25">
<a href="javascript:opennew(<%=rs("id")%>)">
<%=replace(rs("vname"),vname,"<font color=red>"&vname&"</font>")%>
</a>
</td>
<td align=center width="197" height="25"><%=rs("vcontent")%></td>
<%else%>
<td align=center width="203" height="25">
<a href="javascript:opennew(<%=rs("id")%>)">
<%=replace(rs("vname"),vname,"<font color=red>"&vname&"</font>")%>
</a>
</td>
<td align=center width="197" height="25"><%=rs("vcontent")%></td>
</tr>
<%end if%>
<% i=i+1
if i>=MaxPerPage then exit do
rs.movenext
loop
%></tr>
</table>
</div>
<%
end sub
function showpage(totalnumber,maxperpage,filename,vtype)
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 "<p align='center'>分页 "
if CurrentPage<2 then
response.write "首页 上一页 "
else
response.write "<a href="&filename&"?page=1&vname="&vtype&">首页</a> "
response.write "<a href="&filename&"?vname="&vtype&"&page="¤tPage-1&">上一页</a> "
end if
if n-currentpage<1 then
response.write " 下一页 尾页"
else
response.write "<a href="&filename&"?vname="&vtype&"&page="&(CurrentPage+1)
response.write ">下一页</a> <a href="&filename&"?vname="&vtype&"&page="&n&">尾页</a>"
end if
response.write " 页次:<strong><font color=red>"¤tPage&"</font>/"&n&"</strong>页 "
response.write " 共<b>"&totalnumber&"</b>条信息 <b>"&maxperpage&"</b>条信息/页 "
response.write " 转到:<input type='text' name='page' size=4 maxlength=10 class=smallInput value="¤tpage&">"
response.write "<input class=buttonface type='submit' value='Go' name='cndok'></span></p></form>"
end function
%>
</td>
</tr>
</table>
<hr align=center color=#FFE1A4 noShade size=1 >
<p align=center>Written by freezwy</p>
</div>
=======================================================================
最好多加几条记录测试,我这里通过.
freezwy 2001-05-19
  • 打赏
  • 举报
回复
咋不加分呢.好害也忙活着调试了
xiaojun2000 2001-05-18
  • 打赏
  • 举报
回复
能否给一点源码呢?
xmlingo 2001-05-18
  • 打赏
  • 举报
回复
分列是数据显示问题
分页是返回数据行问题

例如一页返回40条记录,只要表格控制好任你分成几列,

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧