求一个简单实用的分页程序(asp)

valu 2003-10-20 05:37:57
求一个简单实用的分页程序(asp)
...全文
52 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenmei 2003-10-21
  • 打赏
  • 举报
回复
<%
set rs=server.createobject("adodb.recordset")
sql="select * from liuyan order by id desc"
rs.open sql,conn,1,1
lise=rs.RecordCount

if request("page")<>"" then
page=request("page")
else
page=1
end if
pagenum=int(lise/6)
if lise<>(pagenum*6) then
pagenum=pagenum+1
end if
%>
<td width="144" bgcolor="#6699cc">
<div align="center"><font color="#ffffff">共加入留言<%=lise%>条</font></div>
</td>
<td width="597" bgcolor="#ffcccc">
<div align="center">目前留言<%=lise%>条.
.本留言共<%=pagenum%>页
<%
if page>1 then
%>
<a href="l_yan.asp?page=<%=page-1%>">前一页</a>
<%
end if
if (pagenum-page)>0 then
%>
<a href="l_yan.asp?page=<%=page+1%>">后一页</a>
<%
end if
%>


<%if lise=0 then
response.Write"目前没有用户留言!"
else
for j=0 to ((page-1)*6-1)
rs.movenext
next
i=0
do while not rs.eof and i<6
%>
内容
<%i=i+1
rs.movenext
loop
set rs=nothing
end if
if page>1 then
%>
<a href="l_yan.asp?page=<%=page-1%>">前一页</a>
<%
end if
if (pagenum-page)>0 then
%>
<a href="l_yan.asp?page=<%=page+1%>">后一页</a>
<%end if
%>


liuguozhong 2003-10-21
  • 打赏
  • 举报
回复
分页

数据库:mydb.mdb里有一表:mytable :
id username password
1 ererer erere
2 ererere erer
......................

说明:<br>
AbsolutePage。指定当前的页。<br>

PagePount。返回记录集中的逻辑页数。也就是说共分多少页<br>

PageSize。指定一个逻辑页中的记录个数,缺省值是10。每页显示多少条记录<br>

rs.recordcount 共多少条记录<br>
<%
set conn=Server.CreateObject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&Server.Mappath("mydb.mdb")
set rs=Server.CreateObject("adodb.recordset")
sql="select * from mytable"
rs.open sql,conn,1,1

'***************以上不必多说了吧!!**********************

Rs.Pagesize=5 '设置一页显示多少条记录 如:5条

pnc=request.querystring("pnc")
if pnc<>"" then
rs.absolutepage=CInt(pnc) '当前显示第几页?
else
pnc=1
rs.absolutepage=CInt(pnc)
end if
%>
<table align="center" border="1" width="80%">

<%'*********************开始显示记录了****************
For I=1 To Rs.Pagesize
If Rs.Eof Then
Exit For
End If
%>
<tr>
<td>
<%=rs("username")%>
</td>
<td>
<%=rs("password")%>
</td>

</tr>
<%
next
%>
</table><br>
共有<%=rs.recordcount%>条记录 页号:
<%
if pnc<>1 then
response.write "<a href=""?pnc=1"">第一页</a> <a href=""?pnc="&pnc-1&""">上一页</a>"
end if
for j=1 to rs.pagecount
if j<>CInt(pnc) then '如果不是当前页有链接
%>
<a href="?pnc=<%=j%>">
<%
end if
response.write j
if j<>CInt(pnc) then
response.write "</a> "
end if
next
%>
<%
pnc=CInt(pnc)
if pnc<>rs.pagecount then
response.write "<a href=""?pnc="&pnc+1&""">下一页</a> <a href=""?pnc="&rs.pagecount&""">最后一页</a>"
end if
rs.close
set rs=nothing

%>
hdyd 2003-10-21
  • 打赏
  • 举报
回复


<%
dim oConn, oRS
Set conn = Server.CreateObject("Adodb.Connection")
conn.Open Application("wf_Conniac_hrSQL")
set rs1=server.CreateObject("adodb.recordset")
'sql="select * from jobrequired WHERE enabled='Y' order by rewardmoney desc"

sql="select * from jobrequired WHERE enabled='Y' order by expiredate"

rs1.Open sql,conn,1,1
%>
<meta content='text/html; chaRset=BIG5' http-equiv='Content-Type'>
<html>
<head>
<title>需求職位</title>
<link rel="stylesheet" href="../style.CSS">
</head>

<SCRIPT LANGUAGE="JavaScript">
function AddInfo()
{
document.Form1.action="Addjob.asp";
document.Form1.submit();
}

</SCRIPT>


<body>
<div align=center>

<FORM action="listjob.asp" method=POST name="Form1">



<%
psize=6
rs1.PageSize = cint(psize)

if rs1.RecordCount=0 then
Response.Write ("<p><center>對不起,沒有查到您要的數據!</center></p>")
else

pagen=request("tempage")

if pagen="" then
pagen=1
end if

sa=Request("sa")

if sa="上一頁" then
pagen=pagen-1
elseif sa="下一頁" then
pagen=pagen+1
elseif sa="確定" then
pagen=request("p")
if pagen="" then
pagen=1
end if
end if
rs1.AbsolutePage = pagen
pagebegin=rs1.PageSize*(pagen-1)+1
if rs1.PageSize*pagen<rs1.RecordCount then
pagend=rs1.PageSize*pagen
else
pagend=rs1.RecordCount
end if
end if
total=rs1.PageCount
recordtotal=rs1.RecordCount

Response.Write "全部共有<font color=#ff0000>"&rs1.RecordCount&"</font>條,分<font color=#ff0000>"&total&"</font>頁顯示,當前顯示第<font color=#ff0000>"&pagen&"</font>頁[<font color=#ff0000>"&pagebegin&" </font>- <font color=#ff0000>"&pagend&"</font>]"

'response.end
%>
</FORM>

<table width="95%" border=1 bordercolordark=white bordercolorlight=black cellpadding=1
cellspacing=1 >

<thead>
<tr><td height="35" colspan="13" align="center" width="100%" bordercolorlight="#6699CC" bgcolor="#6699CC">
<p><b><span lang="EN-US" style="font-size:13.0pt;mso-bidi-font-size:
12.0pt;font-family:標楷體;mso-bidi-font-family:"Times New Roman";color:#FFFF99;
mso-font-kerning:1.0pt;mso-ansi-language:EN-US;mso-fareast-language:ZH-TW;
mso-bidi-language:AR-SA">瀏覽需求職位</span></b></p>
</td></tr>
</thead>
<tr bgcolor=#aabbff>
<td width="7%">需求部門</td>
<td width="9%">需求職位</td>
<td width="28%">基本技能要求</td>
<td width="9%">獎勵金額</td>
<td width="6%">需求數量</td>
<td width="6%">已錄取數量</td>


<td width="11%">從事相關工作</td>
<td width="11%">其他</td>
<td width="7%">截止日期</td>
<td width="7%">推薦</td>
</tr>
<% RC=rs1.PageSize
do while not rs1.EOF and RC>0

For I = 1 To psize
If I/2 = INT(I/2) Then
BgColor = "#DFF3ee"
Else
BgColor = "#DFF3FF"
End If

if cint(rs1("rewardmoney")) = 0 then
BgColor = "darkseagreen"
end if


%>
<form name=form<%=i%> action="modify.asp">
<input type="hidden" name="id" value="<%=rs1(0)%>">
<tr bgColor="<%=BgColor%>">

<%
strprofession=trim(rs1("profession"))
strjobdescription = ""
set rs2=server.CreateObject("adodb.recordset")
sql2 = "select jobDescription from jobdescripview where enabled = 'Y' and jobPosName = '" & strprofession &"'" +"order by jobdescription"
rs2.open sql2,conn,1,1
'rs.Open sqlstr,conn1,1,3
iCount=0

'response.write sql2

strjobDescription0 = ""
strjobDescription1 = ""
strjobDescription2 = ""
strjobDescription3 = ""
strjobDescription4 = ""
strjobDescription5 = ""
strjobDescription6 = ""
strjobDescription7 = ""
strjobDescription8 = ""
strjobDescription9 = ""
strjobDescription10 = ""




do while not rs2.eof
'strjobdescription = strjobdescription + rs2("jobDescription") + ";" + "\n"
strjobdescription = strjobdescription + rs2("jobDescription") + " ; " + "<br>"

if icount = 0 then
strjobDescription0 = rs2("jobDescription")
end if

if icount = 1 then
strjobDescription1 = rs2("jobDescription")
end if

if icount = 2 then
strjobDescription2 = rs2("jobDescription")
end if

if icount = 3 then
strjobDescription3 = rs2("jobDescription")
end if

if icount = 4 then
strjobDescription4 = rs2("jobDescription")
end if

if icount = 5 then
strjobDescription5 = rs2("jobDescription")
end if

if icount = 6 then
strjobDescription6 = rs2("jobDescription")
end if

if icount = 7 then
strjobDescription7 = rs2("jobDescription")
end if

if icount = 8 then
strjobDescription8 = rs2("jobDescription")
end if

if icount = 9 then
strjobDescription9 = rs2("jobDescription")
end if

if icount = 10 then
strjobDescription10 = rs2("jobDescription")
end if

iCount=iCount+1
rs2.movenext
loop
rs2.close

'response.write strjobDescription0 & " " & strjobDescription1 & " " & strjobDescription2 & " " & strjobDescription3& " " & strjobDescription4& " " & strjobDescription5& " " & strjobDescription6& " " & strjobDescription7& " " & strjobDescription8& " " & strjobDescription9& " " & strjobDescription10& " "
'response.end

strrequireddepart=trim(rs1("requireddepart"))
strdepartofficerno=trim(rs1("relationemployeeno"))
strrewardmoney=trim(rs1("rewardmoney"))
strnumber=trim(rs1("number"))
strpassednumber=trim(rs1("passednumber"))

strworkyear=trim(rs1("workyear"))
strforeignlanguage=trim(rs1("foreignlanguage"))
strprofessional=trim(rs1("professional"))
strage=trim(rs1("age"))
strxueli=trim(rs1("xueli"))
strexpiredate=trim(rs1("expiredate"))
strrelationjob=trim(rs1("relationjob"))
strmemo=trim(rs1("memo"))
%>


<td><%=strrequireddepart%> </td>

<td><%=strprofession%> </td>
<td><%=strjobdescription%> </td>
<td><%
if len(strrewardmoney) > 1 then
response.write "<font color=#ff0000>" & strrewardmoney & "</font>"
else
response.write strrewardmoney
end if
%> </td>
<td><%=strnumber%> </td>
<td><%=strpassednumber%> </td>

<td><%=strrelationjob%> </td>
<td><%=strmemo%> </td>
<td><%=strexpiredate%> </td>









</tr>
</form>
</tr>
<%RC=RC-1
rs1.MoveNext
If rs1.EOF Then Exit for
Next
loop
%>

</table>
<form name="formn" action="listjob.asp" >
<% if all="on" then %>
<INPUT type="hidden" size="8" name="all" value="on">
<% end if %>
<INPUT type="hidden" size="8" name="name" value="<%=name%>">
<input type="hidden" name="tempage" value="<%=pagen%>">
<%

if pagen>1 then%>
<input type="submit" name="sa" value="上一頁" class=ButtonStyle>
<%end if
if pagen<total then %>
<input type="submit" name="sa" value="下一頁" class=ButtonStyle>
<%end if
if recordtotal>psize then%>

到第<input type="text" name="p" size=5>去
<input type="submit" value="確定" name="sa" class=ButtonStyle>
<% end if%>





</form>
</div>

</body>
</html>
<%
rs1.Close
conn.close
set conn = nothing

%>
baisun 2003-10-21
  • 打赏
  • 举报
回复
on error resume next
myconn="Provider=SQLOLEDB.1;Persist Security Info=True;User ID=baiyu;PWD=;Initial Catalog=baisun;Data Source=bfy"
set conn=server.createobject("adodb.connection")
conn.open myconn
set rs=server.createobject("adodb.recordset")
sql="select a,b,c, from bai"
rs.open sql,conn,1,1
......
valu 2003-10-20
  • 打赏
  • 举报
回复
那么数据库要在哪里调用?
baisun 2003-10-20
  • 打赏
  • 举报
回复
<%
'-------
'分页bfy
'-------
%>
dim page,rscount,pagecount,SNO
const Url="baisun.asp?"
if session("screenWidth")=1024 and session("screenHeight")=768 then '根据分辨率设置显示行数
rs.pagesize=16
elseif session("screenWidth")=800 and session("screenHeight")=600 then
rs.pagesize=11
else
rs.pagesize=19
end if
rscount=rs.recordcount
'pagecount=rs.pagecount
pagecount=cint(rs.pagecount)
page=trim(request("page"))
if page="" then
page=1
end if
page=cint(page)
if page<1 then
page=1
end if
if page>pagecount then
page=pagecount
end if
if request("page")<>"" then rs.absolutepage=page
rowcount=rs.pagesize
if not rs.eof then
rs.movefirst
do while not rs.eof and rowcount>0
......
rowcount=rowcount-1
rs.MoveNext
loop
end if


----------------------------------------
<head>
<style type="text/css">
#bb a { font-size: 9pt; color: #000000; font-family:"Verdana","宋体"; text-decoration:none }
#bb A:link { font-size:9pt;font-family:"Verdana","宋体"} A:visited { font-size: 9pt;font-family:"Verdana","宋体"}
#bb A:active { font-size: 9pt;font-family:"Verdana","宋体"}
#bb a:hover { font-size: 9pt;font-family:"Verdana","宋体"; color: #ff0000; text-decoration: underline}
.bb {FONT-SIZE: 12px; FONT-FAMILY: "宋体"; COLOR: #000000;}
.input { font-size: 9pt;color:#000000; background-color: #ffffff; border: #003366; border-style: solid;border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px;font-family:"宋体"}
</style>
</head>

<table width="512" height="9" class=bb id=bb>
<tr><form name="frmp" action="" method="post">
<td width="504" height="5">
<font face="宋体">有<%=rscount%>条记录
共<%=pagecount%>页
<font color="#000000">
<%if page>1 then%> <a href=<%=url%>page=1>首页</a><%end if%>
<%
if page-1>0 then %>
</font>
<a href="<%=url%>page=<%=page-1%>"><font color="#FF0000">上一页</font></a>
<%end if%>
<%
if cint(page)<cint(rs.pagecount) then
%>
<a href="<%=url%>page=<%=page+1%>"><font color="#FF0000">下一页</font></a>
<%end if%>
<%if page<>pagecount and pagecount<>0 then%>
<a href=<%=url%>page=<%=pagecount%>>末页</a><%end if%> <font color="#33cc33"><%=page%></font>/<font color="#000000"><%=pagecount%></font>  
转到</font><font size="1"><input type="text" name="page" size="4" class=input onkeyup='javascript:this.value=this.value.replace(/\D/gi,"");' maxlength="6">
<img src="../images/go.gif" onclick="javascript:window.location.href='<%=url%>SNO=<%=SNO%>&page='+frmp.page.value;" style="CURSOR: hand" title="到指定页"></font></td></form></tr>
</table>
baisun 2003-10-20
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/topic/2365/2365782.xml?temp=.1001245

28,390

社区成员

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

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