<!--#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 & "首页 上页 "
'strTemp=strTemp & "<a href='" & sfilename & "intCurrentPage=1'>首页</a> "
else
strTemp=strTemp & "<a href='" & sfilename & "intCurrentPage=1'>首页</a> "
strTemp=strTemp & "<a href='" & sfilename & "intCurrentPage=" & (CurrentPage-1) & "'>上页</a> "
end if
if n-currentpage<1 then
strTemp=strTemp & "下页 尾页"
else
strTemp=strTemp & "<a href='" & sfilename & "intCurrentPage=" & (CurrentPage+1) & "'>下页</a> "
strTemp=strTemp & "<a href='" & sfilename & "intCurrentPage=" & n & "'>尾页</a>"
end if
strTemp=strTemp & " <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
%>