asp和mysql分页代码

来源:互联网 发布:程序员常去的网站集合 编辑:程序博客网 时间:2024/06/05 14:14

 <!--#include file="zheboconn.asp"-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312" />
<title>asp和mysql分页代码</title>
<style type="text/css">
<!--

.STYLE3 {
 font-size: 15px;
 font-family: "宋体";
 color: #000000;
}
img{border:none}
.STYLE1 {
 font-family: "文鼎CS中黑";
 color: #ffffff;
 font-size: 18px;
}
-->
</style>
</head>
<body scroll="no"> //去掉滚动条
  <table width="97%" border="0" align="center" scroll="no">
    <tr>
      <td height="35" valign="top"><%
'asp+mysql分页

Dim strSql,Rs
Dim intRecordNum,intCurrentPage,intRowcount
Dim intPageCount:intPageCount = 5  '每页5条记录
intRowcount = 0

'获得总记录
Set Rs = Conn.Execute("SELECT COUNT(*) As intcounts FROM  表名")               
If Rs.Eof And Rs.Bof Then
 intRecordNum = 0
Else
 intRecordNum = Cint(Rs("intcounts"))
End If

Dim intTotalPages

If (intRecordNum mod intPageCount)>0 Then
 intTotalPages = Int(intRecordNum/intPageCount) + 1
Else
 intTotalPages = intRecordNum/intPageCount
End If

intCurrentPage = 1

If IsEmpty(Request("intCurrentPage")) Or IsNull(Request("intCurrentPage")) Or Trim(Request("intCurrentPage"))="" Or (Not IsNumeric(Request("intCurrentPage"))) Or Len(Request("intCurrentPage"))>8 Then
 intCurrentPage = 1
ElseIf Clng(Request("intCurrentPage")) < 1 Then
 intCurrentPage = 1
ElseIf Clng(Request("intCurrentPage")) > intTotalPages Then
 intCurrentPage = intTotalPages
Else
 intCurrentPage = Clng(Request("intCurrentPage"))
End If


Set Rs = Nothing
Set Rs = Server.CreateObject("ADODB.RecordSet")
strSql = "SELECT * FROM  表名  Order By id DESC LIMIT " & (intCurrentPage - 1) * intPageCount & "," & intPageCount
Rs.Open strSql,Conn
%>
<%
do while not rs.eof
%>
<%Dim t,h                
t=DateDiff("h",rs("表中开始时间字段"),now())'t>0时间已经到了
h=dateDiff("h",rs("表中结束时间字段"),now())',h<0在范围内,h>0,时间已经过了%>


                           <%if t>=0  and  h<=0 then %>
                         
          <table h width="616" border="0" align="center" cellpadding="3" cellspacing="1">
      <tr>
                <a href="d_1.asp?id=<%=Rs("id")%>"><td width="616" height="58" align="center" valign="middle" class="td09" ><span class="STYLE1">
                 <%=Left(Rs("title"),30)%>
                </span></td>
            </a>
            </tr>
          </table> <br>
<%end if
 if not rs.eof then rs.movenext
loop
%>

</td>
    </tr>
  </table>
<%
afile="?Action=Contr2&"
showpage afile,intRecordNum,intPageCount,intCurrentPage
Rs.Close
Set Rs = Nothing
Set objPage = Nothing
%>
<%
sub showpage(sfilename,totalnumber,maxperpage,currentpage)
 dim n, i,strTemp
 if totalnumber mod maxperpage=0 then
     n= totalnumber / maxperpage
   else
     n= totalnumber / maxperpage+1
   end if
   strTemp = "<table width=100%  height=100%  valign='middle' align='center'><form name='showpages' method='Post' action='" & sfilename & "'><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
   'strTemp = strTemp&"Total:"&totalnumber&" "
   if CurrentPage<2 then
      strTemp=strTemp & "<a href='" & sfilename & "intCurrentPage=1''  onFocus=this.blur()><img src=images/s.gif border=0/></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
   else
      'strTemp=strTemp & "<a href='" & sfilename & "intCurrentPage=1'><img src=images/s.png border=0/>;"
      strTemp=strTemp & "<a href='" & sfilename & "intCurrentPage=" & (CurrentPage-1) & "'  onFocus=this.blur()><img src=images/s.gif border=0/></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
   end if
   if n-currentpage<1 then
      strTemp=strTemp & "<a href='" & sfilename & "intCurrentPage=" & n & "'  onFocus=this.blur()><img src=images/x.gif border=0/></a>"
   else
      strTemp=strTemp & "<a href='" & sfilename & "intCurrentPage=" & (CurrentPage+1) & "'  onFocus=this.blur()><img src=images/x.gif border=0/></a>;"
      'strTemp=strTemp & "<a href='" & sfilename & "intCurrentPage=" & n & "'><img src=images/x.png border=0/></a>"
   end if
    ' strTemp=strTemp & "&nbsp;<strong><font color=red>" & CurrentPage & "</font>/" & n & "</strong>y "
     strTemp=strTemp & "</td></tr></form></table>"
     response.write strTemp
End sub
%>

</body>
</html>

原创粉丝点击