用ASP怎样写分页显示数据库?高分求助!!

zhengshier 2003-02-12 11:49:06
我是一个ASP初学者,对ASP写分页显示的程序一直不明白,想请各位大哥大姐帮帮忙?能否给我一个完整的数据库分页显示的程序。第一页都有"首页,上一页,下一页,尾页"等。谢谢!!!!
...全文
208 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
allforly 2003-02-12
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/topic/1400/1400886.xml?temp=.3571894
yufeizhan 2003-02-12
  • 打赏
  • 举报
回复
<%
sql="select * from guest order by id desc"
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
if rs.eof and rs.bof then
response.write "<p align=center>还 没 有 任 何 留 言</p>"
else
'分页的实现
listnum=12
Rs.pagesize=listnum
page=Request("page")
if (page-Rs.pagecount) > 0 then
page=Rs.pagecount
elseif page = "" or page < 1 then
page = 1
end if
Rs.absolutepage=page
'编号的实现
j=rs.recordcount
j=j-(page-1)*listnum

i=0
do while not rs.eof and i<listnum
%>

...


<%
rs.movenext
i=i+1
j=j-1
loop
%>
<table width="650" height="17" align=center cellpadding="0" cellspacing="0" class="bodytablebottom"><tr><%
filename="index.asp"
response.write "<form method=post action="&filename&">"
%>
<td width="100%"> 总计留言<%=Rs.recordcount%>条 共有<%=page%>/<%=Rs.pagecount%>页
<% if page=1 then %>
<%else%>
<a href=<%=filename%>?page=<%=page-1%>>上一页</a> 
<%end if%>
<% if Rs.pagecount-page <> 0 then %>
<a href=<%=filename%>?page=<%=page+1%>>下一页</a> 
<%else%>
<%end if%>
<%
response.write "转到:<input class=smallInput type='text' name='page' size=4 maxlength=10 value="&page&">"
response.write "<input class=noborder type='submit' value='Go' name='cndok'>"
%>
</td>
<%end if%></tr></form>
</table>
csdntoll 2003-02-12
  • 打赏
  • 举报
回复
不怕头晕的话,可以看看:

<!--#include file="admin_check.asp" -->
<% Title="会员管理" %>
<!--#include file="admin_head.asp" -->
<!--#include file="admin_error.asp"-->
<%
if request.querystring("page")="" then
ipagecurrent=1
else
ipagecurrent=cint(request.querystring("page"))
end if

%>

<br>
<p align=left>      <b><a href="admin_membersearch.asp"><font color="#ff0000">查找会员</font></a></b></p>
<table width="90%" border="0" cellspacing="1" cellpadding="4" bgcolor="#000000">
<tr align="center" bgcolor="#C4E9FF" valign=bottom>
<td width="15%" height="22"><b>用户名</b></td>
<td width="10%" height="22"><font class=t><b>Surname</b></font></td>
<td width="15%" height="22"><font class=t><b>First name</b></font></td>
<td width="20%" height="22"><b>手提电话</b></td>
<td width="30%" height="22"><font class=t><b>Email</b></font></td>
<td width="10%" height="22">删 除</td>
</tr>
<%
dim conn,rs
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("user.mdb")
set rs=server.createobject("adodb.recordset")

sql="select userID,username,surname,firstname,mobile,email from personal order by username"
rs.pagesize = 20
rs.cachesize = 20
rs.open sql,conn,1,1

ipagecount = rs.pagecount
If ipagecurrent > ipagecount Then ipagecurrent = ipagecount
If ipagecurrent < 1 Then ipagecurrent = 1
if ipagecount=0 then
response.write "没有任何数据"
else
rs.absolutepage = ipagecurrent
irecordsshown = 0
do while irecordsshown<20 and NOT rs.EOF
if irecordsshown mod 2 = 0 then
%>
<tr bgcolor="#e6eef6" class=t>
<td width="15%" height="23"><a href="admin_memberinfo.asp?userid=<%=rs("UserID")%>"><%=rs("username")%></a></td>
<td width="10%" height="23"><%=rs("surname")%></td>
<td width="15%" height="23"><%=rs("firstname")%></td>
<td width="20%" height="23"><%=rs("mobile")%></td>
<td width="30%" height="23"><a href="mailto:<%=rs("email")%>"><%=rs("email")%></a></td>
<td width="10%" height="23" align="center"><a href="admin_memberdel.asp?userid=<%=rs("UserID")%>"><img src="images/admin_del.gif" border=0></a></td>
</tr>
<%
else
%>
<tr bgcolor="#ffffff" class=t>
<td width="15%" height="23"><a href="admin_memberinfo.asp?userid=<%=rs("UserID")%>"><%=rs("username")%></a></td>
<td width="10%" height="23"><%=rs("surname")%></td>
<td width="15%" height="23"><%=rs("firstname")%></td>
<td width="20%" height="23"><%=rs("mobile")%></td>
<td width="30%" height="23"><a href="mailto:<%=rs("email")%>"><%=rs("email")%></a></td>
<td width="10%" height="23" align="center"><a href="admin_memberdel.asp?userid=<%=rs("UserID")%>"><img src="images/admin_del.gif" border=0></a></td>
</tr>
<%
end if
irecordsshown = irecordsshown +1
rs.MoveNext
loop
end if
%>
</table>
<BR>
<%
Response.Write"<table width='90%' border='0' cellspacing='0' cellpadding='4' class='s'><form name='form1' method='get' action='admin_member.asp'><tr><td height='20' width='120'>共有 <font color='#ff0000'><B>"&rs.recordcount&"</B></font> 位会员 </td><td height='20' align='right'> <B>"&ipagecurrent&"</B>/<B>"&ipagecount&"</B> 页    "
if ipagecurrent=1 then
Response.Write"首页 | "
else
Response.Write"<a href='admin_member.asp?page=1'>首页</a> | "
end if
if ipagecurrent=1 then
Response.Write"上一页 | "
else
Response.Write"<a href='admin_member.asp?page="&ipagecurrent-1&"'>上一页</a> | "
end if
if ipagecount>ipagecurrent then
Response.Write"<a href='admin_member.asp?page="&ipagecurrent+1&"'>下一页</a> "
else
Response.Write"下一页"
end if
if ipagecount>ipagecurrent then
Response.Write" | <a href='admin_member.asp?page="&ipagecount&"'>末页</a> "
else
Response.Write" | 末页 "
end if
Response.Write"</td></tr></table>"
%>
<br><br>

<!--#include file="admin_foot.asp" -->
bluesmile979 2003-02-12
  • 打赏
  • 举报
回复
CS="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("..\db\database.mdb")
DBC.open CS
set RS=Server.CreateObject("ADODB.Recordset")
RS.open "select * from list where user_id='"&user_id&"'",DBC,1,2

set BS=Server.CreateObject("ADODB.Recordset")
BS.open "select * from board where board_no="&board_no&"",DBC,1,2

set DS=Server.CreateObject("ADODB.Recordset")

DS.open "select count(*) from article where board_no="&BS("board_no")&"",DBC,1,2
count=DS(0)
DS.close

DS.open "select count(*) from article where self_no=1 and board_no="&BS("board_no")&"",DBC,1,2
art_count=cint(DS(0))
DS.close

dim recount() 'カィメ衞ラ・
redim recount(art_count) 'ヨリカィメ衞ラ鬟ャホェチヒモテア菽ソカィメ衞センエ。
for i=1 to art_count
DS.open "select count(*) from article where art_no="&i&" and board_no="&BS("board_no")&""
recount(art_count+1-i)=DS(0)-1
DS.close
next 'スォク簧トユツオトサリクエハチソクウクラ魴トマ獗ヲオトヤェヒリ
%>
<b><center><font size=5 face="ソャフ蘋GB2312">タクトソ:<%=BS("board_name")%></font></center></b>
<%

if count=0 then
%>
<b><center><font size=3 face="ソャフ蘋GB2312">アセタクトソトソヌーテサモミホトユツ</center></b>
<a style=text-indent:150 href="post.asp?board_no=<%=board_no%>">キ「ムヤ</a></font>
<%
else
%>

<%
DS.open"select * from article where board_no="&BS("board_no")&" and self_no=1 order by write_time desc"
'aspヨミオトキヨメウシシハャPageSize,PageCount,AbsolutePageカシハヌrecordsetオトハヤ
DS.pagesize=20

if not IsEmpty(Request.QueryString("ToPage")) then
DS.AbsolutePage = ToPage
else
DS.MoveFirst
DS.AbsolutePage = 1
end if
Current_Page = DS.AbsolutePage
%>
<table width=80% align=center>
<td width=40% align=left>
<font size=2>
オレ<font color=#3333FF><b><%=Current_Page%></b></font>メウ/ケイ<font color=#3333FF><b><%=DS.PageCount%></b></font>メウ 
ケイモミ<font color=#3333FF><b><%=art_count%></b></font>ニェホトユツ
</font>
</td>
<td width=40% align=right>
<font size=3 face="ソャフ蘋GB2312">
<a href="post.asp?board_no=<%=board_no%>">キ「ムヤ</a>
</font>
</td>
</table>
<table align=center width=80% border=1 >
<tr>
<td width=4% align=center><font size=2>ミナ</font></td>
<td width=33% align=center><font size=2>ア・・/font></td>
<%
if user_kind=0 then
j=1
else
set SS=Server.CreateObject("ADODB.Recordset")
for i=DS.pagesize*(DS.pagecount-current_page+1) to 1+(DS.pagecount-current_page)*DS.pagesize step -1
if i<=art_count then
SS.open "select * from article where board_no="&BS("board_no")&" and self_no=1 and art_no="&i&"",DBC,1,2
if user_id=SS("author") then
j=1
end if
SS.close
end if
next
end if

if user_kind=0 then
%>
<td width=3% align=right><font size=2>ラェフ・/font></td>
<%
end if

if j=1 then
%>
<td width=10% align=center><font size=2>イルラ・/font></td>
<%
end if
%>
<td width=10% align=center><font size=2>ラ゚</font></td>
<td width=15% align=center><font size=2>ハアシ・/font></td>
<td width=5% align=center><font size=2>サリクエ</font></td>
</tr>
<%
call display_page(DS,current_page,j)

%>

<center>

<% if Current_Page <> 1 then %>
<a href=board.asp?ToPage=1&board_no=<%=board_no%>><font size=2>オレメサメウ</font></a>
<a href=board.asp?ToPage=<%=Current_Page-1%>&board_no=<%=board_no%>><font size=2>ノマメサメウ</font></a>
<%
end if
if Current_Page <>DS.PageCount then
%>
<a href=board.asp?ToPage=<%=Current_Page+1%>&board_no=<%=board_no%>><font size=2>マツメサメウ</font></a>
<a href=board.asp?ToPage=<%=DS.PageCount%>&board_no=<%=board_no%>><font size=2>ラ鋓サメウ</font></a>
<%end if%>
<%end if%>
<a href="show.asp?judge=1">
<font size=2>キオサリツロフウ</a></font>
<a href="..\default.asp">
<font size=2>ヘヒウロフウ</a></font>

</center>


<hr align=center width=80% size=2 color=#000000>

<center><font size=2>BlueSmileケ、ラメー貶ィヒミ</font></center>
</BODY>
</HTML>
bluesmile979 2003-02-12
  • 打赏
  • 举报
回复
现在不怎么用asp了,下面程序写过很久了,你看看吧

因为我是日文系统,中文变乱码了,不好意思。

<%
sub Display_Page(DS, page,view)
DS.AbsolutePage=page
j=view

for i=1 to DS.PageSize
if not DS.EOF then
%>
<tr>
<td width=4% align=center><font size=2><%=i+(page-1)*DS.pagesize%></font></td>

<td width=32% align=left><font size=2>
<a href="article.asp?board_no=<%=board_no%>&art_no=<%=DS("art_no")%>&title=<%=DS("title")%>&ToPage=<%=DS.AbsolutePage%>"><%=DS("title")%></a></font>
</td>
<%
if user_kind=0 then
%>
<td width=5% align=right>
<font size=2><a href="..\manage\art_move.asp?board_no=<%=board_no%>&art_no=<%=DS("art_no")%>&to_page=<%=DS.AbsolutePage%>">ラェフ・/a></font>
</td>
<%
end if
%>
<%
if j=1 then
if user_id=DS("author") or user_kind=0 then
%>
<td width=9% align=center>
<font size=2>
<a href="art_del.asp?art_no=<%=DS("art_no")%>&self_no=<%=DS("self_no")%>&board_no=<%=board_no%>&author=<%=DS("author")%>&ToPage=<%=DS.AbsolutePage%>">
ノセウ</a> 
</font>
<a href="..\manage\alter.asp?judge=2&art_no=<%=DS("art_no")%>&self_no=<%=DS("self_no")%>&board_no=<%=board_no%>&author=<%=DS("author")%>&ToPage=<%=DS.AbsolutePage%>">
<font size=2>ミ゙クト</font></a>
</td>
<%
else
%>
<td width=5%> </td>
<%
end if
end if
%>
<td width=10% align=center><font size=2>
<a href="author.asp?author=<%=DS("author")%>" target=blank><%=DS("author")%>
</a></font></td>
<td width=15% align=center><font size=2><%=DS("write_time")%></font></td>
<td width=5% align=center><font size=2><%=recount(i+(page-1)*DS.pagesize)%></font></td>
</tr>
<%
DS.MoveNext
end if
Next
Response.Write "</table>"
end sub
'ユ篋ッハ」ャハヌモテタエヤレキヨメウケウフヨミハ菠・ソメウオトトレネン
%>
<HTML>
<HEAD>
<TITLE>ACCPムァハロフウ</TITLE>
</HEAD>
<BODY>
<br>
<b><h1><center><font face="ソャフ蘋GB2312" color=#006666>ACCPムァハロフウ--フヨツロヌ・/font></center></h1></b>
<hr align=center width=80% size=2 color=#000000>
<%
user_id=session("user_id")
user_key=session("user_key")
user_kind=session("user_kind")
board_no=request.querystring("board_no")

ToPage=cint(request.querystring("ToPage"))
%>


<hr align=center width=80% size=2 color=#000000>
<%
set DBC=Server.CreateObject("ADODB.Connection")

28,391

社区成员

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

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