MYSQL分页完整可用代码(张建慧)



<!--#Include File=conn.asp-->
<%
'asp+mysql分页

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

'获得总记录
Set Rs = Conn.Execute("SELECT COUNT(*) As intcounts FROM t_confinfo where ConfId>0")

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 t_confinfo where confid>0 Order By ConfId DESC LIMIT " & (intCurrentPage - 1) * intPageCount & "," & intPageCount
Response.write strsql&"<br>"
Rs.Open strSql,Conn,1,1


'If Rs.Eof And Rs.Bof Then

'Else
' Do While Not Rs.Eof And intRowcount < intPageCount
'  intRowcount = intRowcount+1
'  Rs.MoveNext
' Loop
'End If

'ShowPageNum intRecordNum,intTotalPages,intCurrentPage,intPageCount,objPage.txtScriptName,"?"
%>
<%
do while not rs.eof
%>
 <%=Rs("confname")%><br>
<%
 if not rs.eof then rs.movenext
loop
%>


<%
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% align='center'><form name='showpages' method='Post' action='" & sfilename & "'><tr><td>"
 strTemp = strTemp&"Total:"&totalnumber&" "
   if CurrentPage<2 then
      strTemp=strTemp & "首页 上页&nbsp;"
  'strTemp=strTemp & "<a href='" & sfilename & "intCurrentPage=1'>首页</a>&nbsp;"
   else
      strTemp=strTemp & "<a href='" & sfilename & "intCurrentPage=1'>首页</a>&nbsp;"
      strTemp=strTemp & "<a href='" & sfilename & "intCurrentPage=" & (CurrentPage-1) & "'>上页</a>&nbsp;"
   end if

   if n-currentpage<1 then
      strTemp=strTemp & "下页 尾页"
   else
      strTemp=strTemp & "<a href='" & sfilename & "intCurrentPage=" & (CurrentPage+1) & "'>下页</a>&nbsp;"
      strTemp=strTemp & "<a href='" & sfilename & "intCurrentPage=" & n & "'>尾页</a>"
   end if
    strTemp=strTemp & "&nbsp;<strong><font color=red>" & CurrentPage & "</font>/" & n & "</strong>页 "


 strTemp=strTemp & "</td></tr></form></table>"
 response.write strTemp
 
End sub
%>

 

Conn.asp的内容

<%
'on error resume next
'StrConn="DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=byyear_db;UID=byyear;PWD=8326970;OPTION=3"


dim IsServerDataBase
IsServerDataBase = 0 '远程数据库为1,本地数据库为0

If IsServerDataBase = 1 Then
 strconnection="driver={mysql odbc 3.51 driver};database=byyear_db;server=221.204.251.194;uid=byyear;password=8326970"
 '无需配置dsn
Else
 strconnection="driver={mysql odbc 3.51 driver};database=byyear_db;server=LocalHost;uid=root;password=root;OPTION=3"
End If
set Conn = server.createobject("adodb.connection")
Conn.open strconnection

%>

<%
'Call TestConn()

'=====================================================================
' 函数名称:TestConn()
' 主要作用:测试数据库是否连接,查询一个表中的数据进行显示
' 使用方法:调用本函数即可:Call TestConn()
'=====================================================================
Sub TestConn()
 Sql="Select * From t_confinfo "
 Set Rs=Server.CreateObject("Adodb.Recordset")
 Set Rs = Conn.Execute(Sql)
 
 If Rs.Eof And Rs.Bof Then Response.Write "NONE"

 Do While Not Rs.Eof
  Response.Write Rs("ConfName")&"<br>"
  If Not Rs.Eof Then Rs.MoveNext
 Loop

 Rs.Close
 Set Rs=Nothing
 Call CloseConn()
End Sub
%>

<%
Sub CloseConn()
 
 Conn.Close
 Set Conn=Nothing
End Sub
%>

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值