有按钮 和无按钮都可以!!!!!
现给你做了一个 呵呵 自己也练练 都快忘了
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file = "conn.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<%
'声明了drecord(单页显示的记录数)
const drecord = 5
'判断page是否有值,如果有值,将page值赋给dpage(当前的页数)
if not isempty(request.QueryString("page")) then
dpage = cint(request.QueryString("page"))
else
'如果dpage没有值,就给dpage初始化 值为1
dpage = 1
end if
%>
</head>
<body>
<%
'创建记录集
set rs = server.CreateObject("adodb.recordset")
sql = "select * from newstable order by id desc "
rs.open sql,conn,1,1
'判断数据库中是否有记录
if rs.eof and rs.bof then
response.Write "对不起,暂时没有新闻!"
else
'有记录,就将记录的总数赋给mrecord(记录的总数)
mrecord = rs.recordcount
'判断一共要分多少页,将页数赋给mpage(总页数)
if (mrecord mod drecord) = 0 then
mpage = mrecord \ drecord
else
mpage = mrecord \ drecord + 1
end if
'判断当前是否是第一页,若不是就将rs记录集下移
if dpage <> 1 then
t = drecord * (dpage -1)
rs.move t
end if
'调用showcontent过程
showcontent
response.Write "<p align = 'left'>信息分页"
'进行for循环,循环输出分页号码
for k = 1 to mpage
if k = dpage then
response.Write "[<b>"&cstr(k)&"</b>]"
else
response.Write "[<b><a href = 'index.asp?page="&cstr(k)&"'>"&cstr(k)&"</a></b>]"
end if
next
'显示出当前页是多少
if isempty(request("page")) then
response.Write "当前为第1页"
else
response.Write "当前为第"&cstr(request("page"))&"页"
end if
'显示出上下翻页功能
if dpage = 1 then
response.Write "<b><a href='index.asp?page="&dpage+1&"'>下一页</a></b>"
elseif dpage = mpage then
response.Write "<b><a href='index.asp?page="&dpage-1&"'>上一页</a></b>"
else
response.Write "<b><a href='index.asp?page="&dpage+1&"'>下一页</a></b>"
response.Write "<b><a href='index.asp?page="&dpage-1&"'>上一页</a></b>"
end if
response.Write "<p>"
end if
'showcontent存储过程
sub showcontent
i = 0
%>
<table width="487" border="0">
<tr>
<td width="151"><div align="center">id</div></td>
<td width="153"><div align="center">title</div></td>
<td width="169"><div align="center">news</div></td>
</tr>
<%do while not rs.eof%>
<tr>
<td><div align="center"><%=rs("id")%></div></td>
<td><div align="center"><%=rs("title")%></div></td>
<td><div align="center"><%=rs("news")%></div></td>
</tr>
<%
'进行判断,确保每也输出的记录数为5条,大于5条立即停止do while循环
i = i + 1
if i >= 5 then
exit do
end if
rs.movenext
loop
%>
</table>
<%
end sub
%>
</body>
</html>
<%
'关闭记录集和断开数据库连接
rs.close
set rs = nothing
conn.close
set conn = nothing
%>
发的有点乱。。。。
<title>无标题文档</title>
<%
'声明了drecord(单页显示的记录数)
const drecord = 5
'判断page是否有值,如果有值,将page值赋给dpage(当前的页数)
if not isempty(request.QueryString("page")) then
dpage = cint(request.QueryString("page"))
else
'如果dpage没有值,就给dpage初始化 值为1
dpage = 1
end if
%>
</head>
<body>
<%
'创建记录集
set rs = server.CreateObject("adodb.recordset")
sql = "select * from newstable order by id desc "
rs.open sql,conn,1,1
'判断数据库中是否有记录
if rs.eof and rs.bof then
response.Write "对不起,暂时没有新闻!"
else
'有记录,就将记录的总数赋给mrecord(记录的总数)
mrecord = rs.recordcount
'判断一共要分多少页,将页数赋给mpage(总页数)
if (mrecord mod drecord) = 0 then
mpage = mrecord \ drecord
else
mpage = mrecord \ drecord + 1
end if
'判断当前是否是第一页,若不是就将rs记录集下移
if dpage <> 1 then
t = drecord * (dpage -1)
rs.move t
end if
'调用showcontent过程
showcontent
response.Write "<p align = 'left'>信息分页"
'进行for循环,循环输出分页号码
for k = 1 to mpage
if k = dpage then
response.Write "[<b>"&cstr(k)&"</b>]"
else
response.Write "[<b><a href = 'index.asp?page="&cstr(k)&"'>"&cstr(k)&"</a></b>]"
end if
next
'显示出当前页是多少
if isempty(request("page")) then
response.Write "当前为第1页"
else
response.Write "当前为第"&cstr(request("page"))&"页"
end if
'显示出上下翻页功能
if dpage = 1 then
response.Write "<b><a href='index.asp?page="&dpage+1&"'>下一页</a></b>"
elseif dpage = mpage then
response.Write "<b><a href='index.asp?page="&dpage-1&"'>上一页</a></b>"
else
response.Write "<b><a href='index.asp?page="&dpage+1&"'>下一页</a></b>"
response.Write "<b><a href='index.asp?page="&dpage-1&"'>上一页</a></b>"
end if
response.Write "<p>"
end if
'showcontent存储过程
sub showcontent
i = 0
%>
<table width="487" border="0">
<tr>
<td width="151"><div align="center">id</div></td>
<td width="153"><div align="center">title</div></td>
<td width="169"><div align="center">news</div></td>
</tr>
<%do while not rs.eof%>
<tr>
<td><div align="center"><%=rs("id")%></div></td>
<td><div align="center"><%=rs("title")%></div></td>
<td><div align="center"><%=rs("news")%></div></td>
</tr>
<%
'进行判断,确保每也输出的记录数为5条,大于5条立即停止do while循环
i = i + 1
if i >= 5 then
exit do
end if
rs.movenext
loop
%>
</table>
<p>
<%
end sub
%>
</p>
<p><a href="javascript:window.close()">关闭窗口</a></p>
</body>
</html>
<%
'关闭记录集和断开数据库连接
rs.close
set rs = nothing
conn.close
set conn = nothing
%>