简单分页函数一 常用
2018-09-06 10:52
复制代码 代码如下:
<%
page=trim(request(page))
maxperpage=40
first=true
last=true
dimrs
setrs=server.CreateObject(adodb.recordset)
sql=selectid,title,add1,cartype,isred,enterdate,hitsfromnewnewswhereclasstype=0andpass=1orderbyiddesc
rs.opensql,conn,1,1
rs.pagesize=maxperpage
totalpage=rs.pagecount
iflen(page)=0then
intpage=1
first=false
else
ifcint(page)<=1then
intpage=1
first=false
else
ifcint(page)>=rs.pagecountthen
intpage=rs.pagecount
last=false
else
intpage=cint(page)
endif
endif
endif
ifnotrs.eofthen
rs.absolutepage=intpage
endif
fora=1tomaxperpage
ifrs.eofthenexitfor
%>
<tr<%if(amod2)=0then
response.writebgcolor=#ffffff
else
response.writebgcolor=#f6f6f6
endif
%>>
<tdheight=20><divalign=center><%=a%></div></td>
<td><divalign=center>
<%add=rs(add1)
substringadd,4
%>
</div></td>
<td>
<ahref=displaynews.asp?id=<%=rs(id)%>>
<%
ifrs(isred)=Truethen
%>
<fontcolor=red>
<%title=rs(title)
substringtitle,20
%></font>
<%else
title=rs(title)
substringtitle,20
%>
<%
endif
%>
</a></td>
<td><divalign=center><%=rs(cartype)%></div></td>
<td><divalign=center>
<%thetime=rs(enterdate)
themon=datepart(m,thetime)
iflen(themon)<2thenthemon=0&themon
theday=datepart(d,thetime)
iflen(theday)<2thentheday=0&theday
ther=themon&-&theday
response.writether
%>
</div></td>
<td><divalign=center><%=rs(hits)%></div></td>
</tr>
<%
rs.movenext
ifrs.eofthenexitfor
next
%>
</table>
<tablewidth=100%border=0cellspacing=0cellpadding=0>
<tr>
<tdheight=5></td>
</tr>
</table>
<tablewidth=100%border=0cellpadding=0cellspacing=0>
<tr>
<tdheight=20bgcolor=#f6f6f6>
<divalign=center>
<%ifrs.pagecount>0then%>
共有<%=rs.recordcount%>条当前页<%=intpage%>/
<%
=rs.pagecount%>
<%endif%>
<%ifintpage>1then%>
<ahref=<%request.ServerVariables(SCRIPT_NAME)%>?
page=1>首页</a>
<%else%>
首页
<%endif%>
<%iffirstthen%>
<ahref=<%request.ServerVariables(SCRIPT_NAME)%>?
page=<%=intpage-1%>>上一页</a>
<%else%>
上一页
<%endif%>
<%iflastandintpage<rs.pagecountthen%>
<ahref=<%request.ServerVariables(SCRIPT_NAME)%>?
page=<%=intpage+1%>>下一页</a>
<%else%>
下一页
<%endif%>
<%ifintpage<rs.pagecountthen%>
<ahref=<%request.ServerVariables(SCRIPT_NAME)%>?
page=<%=rs.pagecount%>>尾页</a>
<%else%>
尾页
<%endif%>
转到
<selectonChange=location=this.options
[this.selectedIndex].value>
<%forb=1tors.pagecount
ifb=intpagethen%>
<optionvalue=<%request.ServerVariables(SCRIPT_NAME)%>?page=<%=b%>selected>
第<%=b%>页</option>
<%else%>
<optionvalue=<%request.ServerVariables(SCRIPT_NAME)%>?page=<%=b%>>第<%=b%>页
</option>
<%endif
next%>
</select>
</div></td>
</tr>
</table>
</body>
<%
rs.close
setrs=nothing
conn.close
setconn=nothing
%>