分页程序帮忙看看?? (在线等带)

renlily 2004-08-02 01:58:37
on error resume next
dim rs
dim sql
dim msg_per_size
msg_per_size = 3
dim StrConn,Conn
set Conn=server.CreateObject ("adodb.connection")
StrConn = "driver={SQL Server};server=(local);UID=sa;PWD=;database=northwind"
Conn.Open strConn
set rs =server.CreateObject ("adodb.recordset")
sql = "SELECT EmployeeID ,"
sql = sql & " LastName ,"
sql = sql & " FirstName "
sql = sql & " FROM Employees"
rs.CursorLocation = 3
rs.PageSize = msg_per_size
rs.Open sql,conn,2,3
if Err.number<>0 then
Response.Write "error database" & Err.description
Err.Clear
else
if not rs.EOF then
totalrec=rs.RecordCount
if rs.RecordCount mod msg_per_size = 0 then
n = rs.RecordCount \ msg_per_size
else
n = (rs.RecordCount \ msg_per_size) + 1
end if
currentpage=Request("page")
if currentpage<>"" then
currentpage=cint(currentpage)
if currentpage < 1 then
currentpage = 1
end if
if Err.number <>"" then
Err.Clear()
currentpage = 1
end if
else
currentpage = 1
end if
if (currentpage*msg_per_size) > totalrec and not (currentpage-1) * msg_per_size < totalrec then
currentpage = 1
end if
rs.AbsolutePage = currentpage
rowcount = rs.PageSize
%>
<tr align=center valign=middle>
<td width=30% align=center>ID</td>
<td width=30% align=center>FirstName</td>
<td width=30% align=center>LastName</td>
</tr>
<% do while not rs.EOF and rowCount > 0 %>
<tr align=center valign=middle>
<td width=30% align=center><%=rs("EmployeeID")%></td>
<td width=30% align=center><%=rs("FirstName")%></td>
<td width=30% align=center><%=rs("LastName")%></td>
</tr>
<% rowcount = rowcount - 1 %>
<% rs.MoveNext %>
<%loop%>
<%end if
end if
set rs = nothing
rs.Close
%>
</table>
<table border=0 align=right>
<tr>
<td align=center valign=middle>
<% call listpages ()%>
</td>
</tr>
</table>
</BODY>
</HTML>
<%
sub listpages()
if n <=1 then exit sub

for i=0 to n\msg_per_size-1
for j=1 to msg_per_size

%>
<font size=2 color="#006600">
<a href="<%=Request.ServerVariables("script_name")%>?page=<%=i*msg_per_size+j %>">[<%=i*msg_per_size+j%>]</a></font>
<% next
next
EndPage=n Mod msg_per_size
for j=1 to EndPage%>

<font size=2 color="#006600">
<a href="<%=Request.ServerVariables("script_name")%>?page=<%=i*msg_per_size+j %>">[<%=i*msg_per_size+j%>]</a></font>
<% next %>
<font size=2 color=black face="arial">
Page:<%=currentpage%>/<%=n%>pages <%=msg_per_size%>notes/page Total:<%=totalrec%>notes</font>
<%end sub%>
...全文
57 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
renlily 2004-08-03
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=shift_jis">
<TITLE></TITLE>
<SCRIPT language="javascript">
function PageFirst()
{
document.MyForm.CurrentPage.selectedIndex=0;
document.MyForm.CurrentPage.onchange();
}
function PagePrior()
{
document.MyForm.CurrentPage.selectedIndex--;
document.MyForm.CurrentPage.onchange();
}
function PageNext()
{
document.MyForm.CurrentPage.selectedIndex++;
document.MyForm.CurrentPage.onchange();
}
function PageLast()
{
document.MyForm.CurrentPage.selectedIndex=document.MyForm.CurrentPage.length-1;
document.MyForm.CurrentPage.onchange();
}

function PageCurrent()
{
document.MyForm.action='newpage.asp?Page='+(document.MyForm.CurrentPage.selectedIndex+1);
document.MyForm.submit();
}
</SCRIPT>
</HEAD>
<BODY bgcolor="#ffffcc">
<%
dim StrConn,Conn
set Conn=server.CreateObject ("adodb.connection")
StrConn = "driver={SQL Server};server=(local);UID=sa;PWD=;database=wpos"
Conn.Open strConn
set rs =server.CreateObject ("adodb.recordset")
'rs.CursorLocation = adUseClient
rs.PageSize = 4
sql="SELECT USER_ID, USER_MEI, MAIL FROM M_USER"
rs.Open sql,conn,3,2
if rs.EOF then
Response.Write ("<font size=2 color=#000080>[there is no data!]</font>")
else
if Request("Currentpage") = "" then
rs.AbsolutePage = 1
else
rs.AbsolutePage = Clng(Request("CurrentPage"))
Response.Write rs.AbsolutePage
Response.End
end if
if rs.PageCount = 1 then
Response.Write ("[First] [Pre] [Next] [Last]")
else
if rs.AbsolutePage = 1 then
Response.Write ("[First] [Pre]")
Response.Write ("[<a href=javascript:PageNext()>Next</a>]")
Response.Write ("[<a href=javascript:PageLast()>Last</a>]")
else
if rs.AbsolutePage = rs.PageCount then
Response.Write ("[Next] [Last]")
Response.Write ("[<a href=javascript:PageFirst()>First</a>]")
Response.Write ("[<a href=javascript:PagePrior()>Pre</a>]")
else
Response.Write ("[<a href=javascript:PageFirst()>First</a>]")
Response.Write ("[<a href=javascript:PagePrior()>Pre</a>]")
Response.Write ("[<a href=javascript:PageNext()>Next</a>]")
Response.Write ("[<a href=javascript:PageLast()>Last</a>]")
end if
end if
end if
'''''''''''''''''''''''''''''''''''''''''''''''''
Response.Write("NO: <select size=1 name=CurrentPage onchange=PageCurrent()>")
for i=1 to rs.PageCount
if rs.AbsolutePage = i then
Response.Write("<option selected>"&i&"</option>")
else
Response.Write ("<option>"&i&"</option>")
end if
next
Response.Write ("</select>page total"&rs.PageCount&" page total "&rs.RecordCount&" piece note </font></p>")
Response.Write ("</form> ")
end if
Response.Write ("<table align=center border=1 cellspacing=1 cellpaddding=1 ")
Response.Write ("bordercolor=#99ccff>")
Response.Write ("<tr bgcolor=#ccccff bordercolor=#000066>")
for i=0 to rs.Fields.Count-1
Response.Write ("<td align=center width=200 height=13>")
Response.Write ("<font size=2>"&rs.Fields(i).Name&"</font></td>")
next
Response.Write ("</tr>")
for i=1 to rs.PageSize
Response.Write ("<tr bgcolor=#99ccff bordercolor=#000066>")
for j=0 to rs.Fields.Count-1
Response.Write ("<td><font size=2>"&rs.Fields(j).Value&"</font></td>")
next
Response.Write("</tr>")
rs.MoveNext
if rs.EOF then exit for
next
Response.Write ("</table>")

%>
</BODY>
</HTML>
这是照你写的分页,不好用,帮忙看看!!!
回复
rehearts 2004-08-02
当下一页的时候,你的记录集没有动,(你这种分页程序需要在翻页的时候移动记录集)

if (currentPage-1)*msg_per_size<totalrec then
rs.move (currentPage-1)*msg_per_size
回复
mynamelj 2004-08-02
<!-- 一段经典的分页程序 -->
<!--
//建议你使用该分页程序,可以大提高程序的灵活性.
//
//
-->
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=gb2312">
<TITLE></TITLE>
<STYLE type="text/css">
BODY{FONT-SIZE:12px}
TH{FONT-SIZE:12px}
TD{FONT-SIZE:12px}
</STYLE>
<SCRIPT type="text/javascript" language="javascript">
//点击[第一页]时响应
function PageFirst()
{
document.MyForm.CurrentPage.selectedIndex=0;
document.MyForm.CurrentPage.onchange();
}
//点击[上一页]时响应
function PagePrior()
{
document.MyForm.CurrentPage.selectedIndex--;
document.MyForm.CurrentPage.onchange();
}
//点击[下一页]时响应
function PageNext()
{
document.MyForm.CurrentPage.selectedIndex++;
document.MyForm.CurrentPage.onchange();
}
//点击[最后一页]时响应
function PageLast()
{
document.MyForm.CurrentPage.selectedIndex=document.MyForm.CurrentPage.length-1;
document.MyForm.CurrentPage.onchange();
}
//选择"第?页"时响应
function PageCurrent()
{
document.MyForm.action='Pages.asp?Page='+(document.MyForm.CurrentPage.selectedIndex+1);
document.MyForm.submit();
}
</SCRIPT>
</HEAD>

<BODY bgcolor="#ffffcc">
<%
'-------------------------------------------------------
'数据库结构说明:
'数据库类型: Access
'数据库文名: database.mdb
'表 名: book
'字 段:id 为自动编号
'其它字段可以任意创建...
'-------------------------------------------------------
'连接Access数据库
Set conn = Server.CreateObject("Adodb.Connection")
Set rs = Server.CreateObject("Adodb.Recordset")
DBPath = Server.MapPath("database.mdb")
conn.open "Driver={Microsoft Access Driver (*.mdb)};DBQ="& DBPath
'设置每页显示10条记录数
rs.PageSize = 10

'执行SQL语句查询
SQLcmd = "Select * From book Order By id Desc"
rs.Open SQLcmd,conn,1,1

IF rs.Eof THEN
Response.Write("<Font size=2>数数据中没记录!</Font>")
ELSE
'指定当前页码
IF Request("CurrentPage") = "" THEN
rs.AbsolutePage=1
ELSE
rs.AbsolutePage=Clng(Request("CurrentPage"))
END IF

'创建表单MyForm方法为Get
Response.Write("<Form method=Get name=MyForm>")
IF rs.PageCount = 1 THEN
Response.Write("[第一页] [上一页] [下一页] [最后一页]")
ELSE
IF rs.AbsolutePage = 1 THEN
Response.Write(" [第一页] [上一页]")
Response.Write(" <A href=javascript:PageNext()>[下一页]</A>")
Response.Write(" <A href=javascript:PageLast()>[最后一页]</A>")
ELSE
IF rs.AbsolutePage = rs.PageCount THEN
Response.Write(" <A href=javascript:PageFirst()>[第一页]</A>")
Response.Write(" <A href=javascript:PagePrior()>[上一页]</A>")
Response.Write(" [下一页] [最后一页]")
ELSE
Response.Write(" <A href=javascript:PageFirst()>[第一页]</A>")
Response.Write(" <A href=javascript:PagePrior()>[上一页]</A>")
Response.Write(" <A href=javascript:PageNext()>[下一页]</A>")
Response.Write(" <A href=javascript:PageLast()>[最后一页]</A>")
END IF
END IF
END IF

'创建下拉列表
Response.Write(" 第<SELECT name=CurrentPage onchange=PageCurrent()>")
FOR i=1 TO rs.PageCount
IF rs.AbsolutePage = i THEN
Response.Write("<option selected>"&i&"</option>") '当前页码
ELSE
Response.Write("<option>"&i&"</option>")
END IF
NEXT
Response.Write("</SELECT>页/共"&rs.PageCount&"页 共"&rs.RecordCount&"条记录")
Response.Write("</FORM>")
END IF
'创建表格,用于显示数据
Response.Write("<TABLE align=center cellspacing=0 cellpadding=0 border=1")
Response.Write(" bordercolor=#000000 style='border-collapse: collapse'>")
Response.Write("<TR bgcolor=#ccccff bordercolor=#000066>")
'显示表头名称
Set Columns=rs.Fields
For i=0 to Columns.Count-1
Response.Write("<TD align=center width=200 height=15>"&Columns(i).name&"</TD>")
NEXT
Response.Write("</TR>")
'显示表内容
FOR i=1 TO rs.PageSize
Response.Write("<TR bgcolor=#99cff>")
FOR j=0 TO Columns.Count-1
Response.Write("<TD>"&Columns(j)&"</TD>")
NEXT
Response.Write("</TR>")
'下一条记录
rs.MoveNext
IF rs.EOF THEN EXIT FOR
NEXT
Response.Write("</TABLE>")
%>
</BODY>
</HTML>
回复
renlily 2004-08-02
翻页时,总显示第一页的三条记录.
不知道为什么??`
回复
相关推荐
发帖
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
帖子事件
创建了帖子
2004-08-02 01:58
社区公告
暂无公告