为什么我弄数据分页显示总弄不好呀

maohuibo 2002-03-29 10:06:31
为什么我弄数据分页显示总弄不好呀
...全文
68 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
maohuibo 2002-03-30
  • 打赏
  • 举报
回复
谢谢你的回答
forestli 2002-03-29
  • 打赏
  • 举报
回复
给你一个简单的离子
<table width="754" border="0" cellspacing="0" cellpadding="1" height="10">
<tr bgcolor="#FFFFCC">
<td width="38">序号</td>
<td width="38">等级</td>
<td width="473">标题</td>
<td width="139">发布时间</td>
<td width="96">操作</td>
</tr>
<%
Dim ps
ps=26
Dim cp
cp=Request.QueryString("cp")
If cp="" then
cp=1
Else
cp=Cint(cp)
End If

Dim conn,sql,rs,vout
dim i,pc
vout=""
set conn=server.CreateObject("ADODB.Connection")
conn.Open "driver={SQL Server};server=**********"
set rs=Server.CreateObject("ADODB.Recordset")
sql="SELECT NID,NTITLE,INTIME,NLEVEL FROM NEWS ORDER BY INTIME DESC"
rs.pagesize=ps
rs.open sql,conn,1
pc=rs.pagecount
If pc<>0 then
vout=vout+"共"& pc &"页 - "&rs.recordcount &"条记录"
rs.absolutepage=cp
for i=1 to ps
If rs.eof then
Exit for
End If
vout=vout + "<tr>"
vout=vout + "<td>"& i+(cp-1)*ps &"</td><td>"& rs("nlevel") &"</td><td>"& rs("ntitle") &"</td><td>"& rs("intime") &"</td><td><a href=/news/deletenews.asp?nid="& rs("NID") &">删除</a> - <a href=/news/x_news.asp?nid="& rs("NID") &">修改</a></td></tr>"
rs.MoveNext
If rs.eof then
Exit for
End If
i=i+1
vout=vout + "<tr bgcolor=#ffffcc>"
vout=vout + "<td>"& i+(cp-1)*ps &"</td><td>"& rs("nlevel") &"</td><td>"& rs("ntitle") &"</td><td>"& rs("intime") &"</td><td><a href=/news/deletenews.asp?nid="& rs("NID") &">删除</a> - <a href=/news/x_news.asp?nid="& rs("NID") &">修改</a></td></tr>"
rs.MoveNext
Next
vout=vout + "<tr><td colspan=4>"
vout=vout + "<a href=/admin/news/menu.asp?cp=1>首页</a>"
If cp > 1 Then
vout=vout + " - <a href=/admin/news/menu.asp?cp="& cp-1 &">前页</a>"
End If
If cp < pc Then
vout=vout + " - <a href=/admin/news/menu.asp?cp="& cp+1 &">后页</a>"
End If
vout=vout + " - <a href=/admin/news/menu.asp?cp="& pc &">尾页</a>"
vout=vout + "</td></tr>"
response.write vout
Else
response.write "没有记录!"
End If
set vout=nothing
set i=nothing
set pc=nothing
set cp=nothing
set ps=nothing
rs.close
set rs=nothing
conn.close
set conn=nothing
set sql=nothing
%>
</table>
jinhaiou 2002-03-29
  • 打赏
  • 举报
回复
<%
page=Request.QueryString("page") '取page值

'数据库中查询
Set conn=Server.CreateObject("ADODB.Connection")
sql="select * from table"
Set rs=conn.Execute(sql)

rs.PageSize=30 '设置分的页数,设好后系统会自动将rs.PageCount计算出来

If Page<1 Then Page=1
If Page=null Then Page=1
If Page>rs.PageCount Then Page=rs.PageCount 'rs.PageCount是总页数

rs.AbsolutePage=page '将要显示的页数

If page<>1 Then
Response.Write"<a href=show.asp?page=1>首页</a>"
Response.Write"<a href=show.asp?page="&(page-1)前页</a>"
End If
If page<>rs.PageCount Then
Response.Write"<a href=show.asp?page="&(page+1)>后页</a>"
Response.Write"<a href=show.asp?page="&rs.PageCount>尾页</a>"
End If

'显示分页
For iPage=1 To rs.PageSize
%>
<%=rs("显示字段")%>
<%rs.MoveNext '若到尾部则跳出
If rs.EOF Then Exit For
Next
%>
jinhaiou 2002-03-29
  • 打赏
  • 举报
回复
參考:
<%Server.ScriptTimeout=600
n=Year(Date())
y=Month(Date())
r=Day(Date())
s=Hour(time())
f=Minute(time())
m=Second(time())
if len(s)=1 then s="0" & s
if len(f)=1 then f="0" & f
if len(m)=1 then m="0" & m
sj = s & ":" & f & ":" & m
sj2= n & "-" & y & "-" & r & " " & sj
Dim CurPage
If Request.QueryString("CurPage") = "" then
CurPage = 1
Else
CurPage = CINT(Request.QueryString("CurPage"))
End If
display = CurPage

Set Conn = Server.CreateObject("ADODB.Connection")
Set RS = Server.CreateObject("ADODB.RecordSet")
Conn.Open "sa","",""
SQL="select Name,Exp,Ltime from yiminchat order by Exp DESC"
RS.Open SQL, Conn,1,1

RS.PageSize=20


if rs.EOF and rs.BOF Then
Response.write "<html><head><title>没有记录</title><meta http-equiv='Content-Type' content='text/html; charset=gb2312'></head>"
Response.write "<body><table width='364' cellpadding='10' align='center'><tr align='center'><td>"
Response.write "<p><font color='#FF0000' style='font-size: 12pt'>没有记录</font></p>"
Response.write "<p><a href='javascript:history.go(-1)'>点击此处返回</a></p>"
Response.write "</td></tr></table></body></html>"
Response.End
Else

'计算最多有多少页
Dim TotalPages
TotalPages = RS.PageCount

if CurPage>RS.Pagecount then
CurPage=RS.Pagecount
end if

RS.AbsolutePage=CurPage

'设置缓存大小 = 每页需显示的记录数目
rs.CacheSize = RS.PageSize

'计算最多有记录
Dim Totalcount
Totalcount =INT(RS.recordcount)

StartPageNum=1
do while StartPageNum+20<=CurPage
StartPageNum=StartPageNum+20
Loop

EndPageNum=StartPageNum+19

if EndPageNum>RS.Pagecount then EndPageNum=RS.Pagecount%>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type='text/css'>
<!--
.p9{line-height: 170%;font-size:9pt;text-decoration: underline;}
.p12 {line-height: 170%; font-size:9pt;text-decoration: underline;}
body {line-height: 170%;font-size : 9pt;text-decoration: none;}
td {line-height: 170%;font-size : 10.5pt;text-decoration: none;}
A:{text-decoration : none;}
A:Hover {text-decoration : none; color="#0000ff"}
A:active {text-decoration : none; color="#0000ff"}
A:visited{ color="#ff7120"}
-->
</style>
<script language="javaScript">
function load()
{var name=navigator.appName
var vers=navigator.appVersion
if(name=="Netscape")
{window.location.reload()
}else
{history.go(0)
}}</script>
</head>
<body bgcolor="#FFFFFF">
<h1 align="center"><font color="#0099FF"><a name="begin"></a>【聊 神 榜】</font></h1>
<hr noshade size="1" color=#009900>
<form method="post" action="">
<div align="center">
<input type="button" value="刷新" onClick=load() style="font-size:9pt" name="button">
</div>
</form>
<p><b>[铁杆聊神排行榜]</b> 共有注册名 <font color="#FF0000"><b><%=Totalcount%></b></font>
个 刷新时间:<%=sj2%>
<p>
<hr noshade size="1" color=#009900>
<table border="1" width="75%" bgcolor="#FFCC33" bordercolordark="#FFFFFF" bordercolorlight="#000000" align="center">
<tr>
<td bgcolor="#0066FF">
<div align="center"><b><font color="#FFFFFF">名次</font></b></div>
</td>
<td bgcolor="#0066FF">
<div align="center"><b><font color="#FFFFFF">用 户 名</font></b></div>
</td>
<td bgcolor="#0066FF">
<div align="center"><b><font color="#FFFFFF">经 验 值</font></b></div>
</td>
<td bgcolor="#0066FF">
<div align="center"><b><font color="#FFFFFF">最后登陆时间</font></b></div>
</td>
</tr>
<tr> <%I=0
p=RS.PageSize*(Curpage-1)
do while (Not RS.Eof) and (I<RS.PageSize)
p=p+1%>
<td align="center"><b><font color="#000000"><% =p%></font></b></td>
<td align="center"><b><font color="#000000"> <%=RS("Name")%></font></b></td>
<td align="center"><b><font color="#000000"> <%=RS("Exp")%></font></b></td>
<td align="center"><b><font color="#000000"> <%=RS("Ltime")%></font></b></td>
</tr>
<%I=I+1
RS.MoveNext
Loop%>
</table>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2">
<hr noshade size="1" color=#009900>
</td>
</tr>
<tr>
<td width="61%"> <% if StartPageNum>1 then %> <a href="listok.asp?CurPage=<%=StartPageNum-1%>"><</a>
<%end if%> <% For I=StartPageNum to EndPageNum
if I<>CurPage then %> <a href="phb.asp?CurPage=<%=I%>"><%=I%></a>
<% else %> <%=I%> <% end if %> <% Next %> <% if EndPageNum<RS.Pagecount then %>
<a href="phb.asp?CurPage=<%=EndPageNum+1%>">></a> <%end if%></td>
<td align="right" width="39%"> <%if CurPage-1>=1 then%> <a href="phb.asp?CurPage=<%=CurPage-1%>"><<上一页</a>
<%end if%> <%if CurPage+1<=RS.Pagecount then%> <a href="phb.asp?CurPage=<%=CurPage+1%>">下一页>></a>
<% end if%> </td>
</tr>
</table>
</td>
</tr>
</table>
<% RS.Close %>
<% end if %>
<% Conn.Close %>
<div align="center">
<hr noshade size="1" color=#009900>
<a href="#begin">返回页首</a></div>
<hr noshade size="1" color=#009900>
</body>
</html
jinhaiou 2002-03-29
  • 打赏
  • 举报
回复
參考:
<%Server.ScriptTimeout=600
n=Year(Date())
y=Month(Date())
r=Day(Date())
s=Hour(time())
f=Minute(time())
m=Second(time())
if len(s)=1 then s="0" & s
if len(f)=1 then f="0" & f
if len(m)=1 then m="0" & m
sj = s & ":" & f & ":" & m
sj2= n & "-" & y & "-" & r & " " & sj
Dim CurPage
If Request.QueryString("CurPage") = "" then
CurPage = 1
Else
CurPage = CINT(Request.QueryString("CurPage"))
End If
display = CurPage

Set Conn = Server.CreateObject("ADODB.Connection")
Set RS = Server.CreateObject("ADODB.RecordSet")
Conn.Open "sa","",""
SQL="select Name,Exp,Ltime from yiminchat order by Exp DESC"
RS.Open SQL, Conn,1,1

RS.PageSize=20


if rs.EOF and rs.BOF Then
Response.write "<html><head><title>没有记录</title><meta http-equiv='Content-Type' content='text/html; charset=gb2312'></head>"
Response.write "<body><table width='364' cellpadding='10' align='center'><tr align='center'><td>"
Response.write "<p><font color='#FF0000' style='font-size: 12pt'>没有记录</font></p>"
Response.write "<p><a href='javascript:history.go(-1)'>点击此处返回</a></p>"
Response.write "</td></tr></table></body></html>"
Response.End
Else

'计算最多有多少页
Dim TotalPages
TotalPages = RS.PageCount

if CurPage>RS.Pagecount then
CurPage=RS.Pagecount
end if

RS.AbsolutePage=CurPage

'设置缓存大小 = 每页需显示的记录数目
rs.CacheSize = RS.PageSize

'计算最多有记录
Dim Totalcount
Totalcount =INT(RS.recordcount)

StartPageNum=1
do while StartPageNum+20<=CurPage
StartPageNum=StartPageNum+20
Loop

EndPageNum=StartPageNum+19

if EndPageNum>RS.Pagecount then EndPageNum=RS.Pagecount%>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type='text/css'>
<!--
.p9{line-height: 170%;font-size:9pt;text-decoration: underline;}
.p12 {line-height: 170%; font-size:9pt;text-decoration: underline;}
body {line-height: 170%;font-size : 9pt;text-decoration: none;}
td {line-height: 170%;font-size : 10.5pt;text-decoration: none;}
A:{text-decoration : none;}
A:Hover {text-decoration : none; color="#0000ff"}
A:active {text-decoration : none; color="#0000ff"}
A:visited{ color="#ff7120"}
-->
</style>
<script language="javaScript">
function load()
{var name=navigator.appName
var vers=navigator.appVersion
if(name=="Netscape")
{window.location.reload()
}else
{history.go(0)
}}</script>
</head>
<body bgcolor="#FFFFFF">
<h1 align="center"><font color="#0099FF"><a name="begin"></a>【聊 神 榜】</font></h1>
<hr noshade size="1" color=#009900>
<form method="post" action="">
<div align="center">
<input type="button" value="刷新" onClick=load() style="font-size:9pt" name="button">
</div>
</form>
<p><b>[铁杆聊神排行榜]</b> 共有注册名 <font color="#FF0000"><b><%=Totalcount%></b></font>
个 刷新时间:<%=sj2%>
<p>
<hr noshade size="1" color=#009900>
<table border="1" width="75%" bgcolor="#FFCC33" bordercolordark="#FFFFFF" bordercolorlight="#000000" align="center">
<tr>
<td bgcolor="#0066FF">
<div align="center"><b><font color="#FFFFFF">名次</font></b></div>
</td>
<td bgcolor="#0066FF">
<div align="center"><b><font color="#FFFFFF">用 户 名</font></b></div>
</td>
<td bgcolor="#0066FF">
<div align="center"><b><font color="#FFFFFF">经 验 值</font></b></div>
</td>
<td bgcolor="#0066FF">
<div align="center"><b><font color="#FFFFFF">最后登陆时间</font></b></div>
</td>
</tr>
<tr> <%I=0
p=RS.PageSize*(Curpage-1)
do while (Not RS.Eof) and (I<RS.PageSize)
p=p+1%>
<td align="center"><b><font color="#000000"><% =p%></font></b></td>
<td align="center"><b><font color="#000000"> <%=RS("Name")%></font></b></td>
<td align="center"><b><font color="#000000"> <%=RS("Exp")%></font></b></td>
<td align="center"><b><font color="#000000"> <%=RS("Ltime")%></font></b></td>
</tr>
<%I=I+1
RS.MoveNext
Loop%>
</table>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="2">
<hr noshade size="1" color=#009900>
</td>
</tr>
<tr>
<td width="61%"> <% if StartPageNum>1 then %> <a href="listok.asp?CurPage=<%=StartPageNum-1%>"><</a>
<%end if%> <% For I=StartPageNum to EndPageNum
if I<>CurPage then %> <a href="phb.asp?CurPage=<%=I%>"><%=I%></a>
<% else %> <%=I%> <% end if %> <% Next %> <% if EndPageNum<RS.Pagecount then %>
<a href="phb.asp?CurPage=<%=EndPageNum+1%>">></a> <%end if%></td>
<td align="right" width="39%"> <%if CurPage-1>=1 then%> <a href="phb.asp?CurPage=<%=CurPage-1%>"><<上一页</a>
<%end if%> <%if CurPage+1<=RS.Pagecount then%> <a href="phb.asp?CurPage=<%=CurPage+1%>">下一页>></a>
<% end if%> </td>
</tr>
</table>
</td>
</tr>
</table>
<% RS.Close %>
<% end if %>
<% Conn.Close %>
<div align="center">
<hr noshade size="1" color=#009900>
<a href="#begin">返回页首</a></div>
<hr noshade size="1" color=#009900>
</body>
</html
希偌 2002-03-29
  • 打赏
  • 举报
回复
我写的例子,关于分页和查询后的分页都有!
http://home.pchome.com.tw/mysite/33360247/select.zip

28,404

社区成员

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

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