如何分页显示问题??

crazyyu 2002-07-30 10:13:33
我从数据库中得到大量数据,以记录集接收,现在想一条条的显示在页面上,但记录条数很多,一页显示不下,我不知道该怎样分页显示,就向某些网站一页显示不完,有下一页那样。谢了
...全文
24 点赞 收藏 3
写回复
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
bobmile 2002-07-30
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>查询结果</title>
</head>
<body>
<%
dim conn
dim connstr
on error resume next
connstr="DBQ="+server.mappath("test.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
conn.open connstr
%>
<%
const MaxPerPage=2
dim totalPut
dim keyword
dim category
dim CurrentPage
dim TotalPages
dim i
dim filename
dim categoryid
keyword=trim(request("keyword"))
%>
<%
if not isempty(request("page")) then
currentPage=cint(request("page"))
else
currentPage=1
end if
filename="result.asp"
dim sql
dim rs

sql="select * from test where productname like '%"&keyword&"%' or introduction like '%"&keyword&"%' or price like '%"&keyword&"%' "

Set rs= Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,1,1
if rs.eof then
response.write "<p align='center'><font size=5 color=red>找不到该关键字的记录</font></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
showContent
showpage totalput,MaxPerPage,filename
else
if (currentPage-1)*MaxPerPage<totalPut then
rs.move (currentPage-1)*MaxPerPage
dim bookmark
bookmark=rs.bookmark
showContent
showpage totalput,MaxPerPage,filename
else
currentPage=1
showContent
showpage totalput,MaxPerPage,filename
end if
end if
rs.close
end if
set rs=nothing
conn.close
set conn=nothing
sub showContent
number=maxperpage*(currentpage-1)+1
dim i
i=0

%>
<p align="center">
<font size="3">查询关键字
<font color="#FF0000"><%=keyword%></font>
</font></p>
<div align="center">
<form method="post" action="result.asp">
<p>请输入搜索关键字:
<input type="text" name="keyword" size="20" maxlength="255" class="smallInput">
<input type="submit" name="Submit" value="查询" class="buttonface">
</p>
</form>
<div align="center"><center>
<table border="0" cellspacing="1" width="80%" cellpadding="1">
<tr bgcolor="#7B96A5">
<td width="10%" align="center" height="20">
<font size="3" color="#FFFFFF">编号</font>
</td>
<td width="50%" align="center">
<font size="3" color="#FFFFFF">产品名称</font><
/td>
<td width="10%" align="center">
<font size="3" color="#FFFFFF">价格</font>
</td>
</tr>
<%do while not rs.eof%>
<tr bgcolor="#C1CDDB">
<td>
<p align="center"><%=number%> </td>
<td><%=rs("productname")%>
</td>
<td align="center"><%if rs("price")="0" then
response.write "面议"
else
response.write rs("price")
end if%> </td>
</tr>
<% i=i+1
number=number+1
if i>=MaxPerPage then exit do
rs.movenext
loop
%>
</table>
</center></div></div>
<%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 "<p align=center><form method=Post action="&filename&"?keyword="&keyword&">"
if CurrentPage<2 then
response.write "<font color='999966'>首页   上一页</font>   "
else
response.write "<a href="&filename&"?keyword="&keyword&">首页</a>   "
response.write "<a href="&filename&"?page="¤tPage-1&"&keyword="&keyword&">上一页</a>   "
end if
if n-currentpage<1 then
response.write "<font color='999966'>下一页   尾页</font>"
else
response.write "<a href="&filename&"?page="&(CurrentPage+1)&"&keyword="&keyword&">下一页</a>  "
response.write " <a href="&filename&"?page="&n&"&keyword="&keyword&">尾页</a>"
end if
response.write "  <font color=red>"¤tPage&"</font>/"&n&" 页 "
response.write " 总共 <font color=red><b>"&totalnumber&"</b></font> 产品"
response.write " 转到:<input type='text' name='page' size=2 maxlength=10 class=smallInput value="¤tpage&">"
response.write "<input class=buttonface type='submit' value='Go' name='cmdok'></span></p></form>"

end function


%>

</body>
</html>
自己试试吧
回复
dapper 2002-07-30
数据库连接的地方改成你自己的就可以用了。
回复
dapper 2002-07-30
<html>
<head>
<% dim DB_CONNECT_STRING
dim curpage
dim DB

curpage = request.QueryString("page")
if curpage<1 then
curpage=1
end if
response.write(curpage)

DB_CONNECT_STRING="DSN=PubCRM;UID=PubCRM;Password=pubcrm;"

set DB = server.createObject("ADODB.connection")
DB.Open DB_CONNECT_STRING
if Err.number <> 0 then
msgbox("エラー:" & Err.Description)
Response.End
end if
%>
<%
Function ExportPageInfo(ByRef rs,curpage,i,linkFile)
dim retval,j,pageNumber,BasePage
retval = "第" & curpage & "頁/総" & rs.pagecount & "頁"
retval = retval & "本頁" & i & "件/総" & rs.recordcount & "件"

if curpage = 1 then
retval = retval & "首頁 前頁"
else
retval = retval & "<a href=" & linkFile & "page=1>首頁</a><a href=" & linkFile & "page=" & cstr(curpage-1) & ">前頁</a>"

end if
if cstr(curpage) = cstr(rs.pagecount) then
retval = retval & "後頁 末頁"
else
retval = retval & "<a href=" & linkFile & "page=" & cstr(curpage+1) & ">後頁</a><a href=" & linkFile & "page=" & cstr(rs.pagecount) & ">末頁</a>"
end if

retval = retval & "<br>"

BasePage = (curpage\10)*10
if BasePage > 0 then
beforepage = basepage - 9
retval = retval & "<a href=" & linkFile & "page=" & beforepage & "><<</a>"
For j=1 to 10
pageNumber = BasePage + j
if pageNumber > rs.pagecount then
exit for
end if
if pageNumber = cint(curpage) then
retval = retval & "<font color='#ff0000'>" & pageNumber & "</font>"
else
retval = retval & "<a href=" & linkFile & "page=" & pageNumber & "</a>"
end if
next
end if
if rs.pagecount > BasePage then

if rs.pagecount <> cint(curpage) then
if (BasePage + 11) > rs.pagecount then
retval=retval & "<a href=" & linkFile & "page=" & rs.pagecount & ">>></a>"
else
retval=retval & "<a href=" & linkFile & "page=" & (BasePage+11) & ">>></a>"
end if
end if
end if
ExportPageInfo = retval
end function
%>
<title>fen ye xian shi</title>
<body>
<h1>a test form </h1>

<% dim RS
dim sql
set RS = server.Createobject("ADODB.recordset")
sql = "select id,book_cod from book"
RS.open sql,DB,1,1
if err.number <> 0 then
response.write("open database err")
else
if RS.eof and RS.bof then
response.write("no data")
else
%>
<div align="center">
<center>
<table width="100%" border="0" cellspacing="1" cellpadding="2">
<tr>
<td>ID</td>
<td>BOOKCODE</td>
</tr>

<%
rs.pagesize=20
rs.absolutepage=curpage
for i= 0 to 19
%>
<tr>
<td><%=rs("Id")%></td>
<td><%=rs("book_cod")%></td>
</tr>
<% rs.movenext
if rs.eof then
i=i+1
exit for
end if
next
%>
<tr>
<td><%=ExportPageInfo(RS,curpage,i,"ExportPageInfo.asp?")%>
</td>
</tr>

<% end if
end if
%>
</table>
<h1> end </h1>
</center>
</div>
</body>
</html>
回复
发动态
发帖子
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
社区公告
暂无公告