当前位置:asp编程网>贴吧>Asp吧>  asp开发工具5自带分页功能出错
lxsanyuelxsanyue 楼主
lxsanyue
发表于 2016-05-31 10:43:24 回顶端 
<%
Function OpenConn() ``连接数据库代码,使用方法conn=OpenConn()
    db="db1.mdb"
    Set fso = Server.CreateObject("Scripting.FileSystemObject")
    If fso.FileExists(server.MapPath(db))=false then
       db="../" & db
    End If
    Set fso = Nothing
    path = server.MapPath(db)
    Dim conn
    Set conn = server.CreateObject("adodb.Connection")
    connstr = "provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & path 
    conn.Open connstr
    Set OpenConn = conn
End Function


Sub CloseConn(Conn) ``关闭数据库代码
    On Error Resume Next
    If IsObject(Conn) then
        Conn.Close()
        Set Conn = Nothing
    End If
    If Err Then Err.Clear
End Sub
%>
<%
``功能防sql注入,包括字符型变量和数字型变量。
``参数:
``ParaName:参数名称——字符型
``ParaType:参数类型——数字型(1表示以上参数是数字,0表示以上参数为字符)
``lenlimit:长度限制
``整理:www.aspbc.com
``原创文章,转载请保留此信息。
Function SafeRequest(ParaName,ParaType,lenlimit)
    Dim ParaValue
    ParaValue = trim(Request(ParaName))
    If ParaType = 1 then
        If IsNull(ParaValue) Or (Not IsNumeric(ParaValue)) then
            ParaValue = cint(lenlimit)
        End if
    Else
        If ParaValue&""="" Then
            ParaValue = ""
        Else
            ParaValue = CheckVar(ParaValue)
        End If
    End If
    SafeRequest = ParaValue
End Function


``功能:将特殊字符转成相应的中文字符
Function CheckVar(byval t)
    t = trim(t&"")
t = replace(t&"","``","`")
t = replace(t&"","""",""")
t = replace(t&"",";",";")
t = replace(t&"",":",":")
t = replace(t&"","%","%")
t = replace(t&"","*","☆")
t = replace(t&"","?","?")
    t = replace(t&"","!!","!")
t = replace(t&"","<","〈")
t = replace(t&"","(","(")
t = replace(t&"","&","&")
t = replace(t&"","##","#")
t = replace(t&"","——","—")
t = replace(t&"","————","——")
CheckVar = t
End Function


``功能:恢复相应的特殊字符
Function ReCheckVar(byval t)
    t = trim(t&"")
    t = replace(t&"","`","``")
    t = replace(t&"",""","""")
    t = replace(t&"",";",";")
    t = replace(t&"",":",":")
    t = replace(t&"","%","%")
    t = replace(t&"","☆","*")
    t = replace(t&"","?","?")
    t = replace(t&"","!","!!")
    t = replace(t&"","〈","<")
    t = replace(t&"","(","(")
    t = replace(t&"","&","&")
    t = replace(t&"","#","##")
    t = replace(t&"","—","——")
    ReCheckVar = t
End Function
%>
<%
``cs参数,用|分割开
``recordnum总记录数
``page 当前页数
``page_size 每页条数
Function Fpages(cs,recordnum,page,page_size)
    dim m:m=3 ``左右超过3个就省略
  dim str:str=""
dim s1
dim url:url=GetUrl()
if instr(url,"?")>0 then
   url=split(url,"?")(0)
end if
s1=split(cs,"|")
dim cs2:cs2=""
for i=0 to ubound(s1)
   cs2=cs2&"&"&cstr(s1(i))&"="&saferequestx(cstr(s1(i)),0,20)
    next
    dim countpage
if recordnum mod page_size=0 then
    countpage=recordnum\page_size
else
countpage=recordnum\page_size+1
end if
``response.write "countpage="&countpage&"==="&page_size
``response.end
    if page*1=1 then
   str=str&"|<<"
else
    str=str&"|<<"
end if
dim s,e
if page——m>0 then s=page——m else s=1
if page+m for i=s to e
    if i*1=page*1 then
   str=str&""&i&""
else
   str=str&""&i&""
end if
next
if page*1 < countpage*1 then
   str=str&">>|"
    else
str=str&">>|"
end if
`` str=str&" 共 "&countpage&" 页"
if countpage<=0 then str = ""
Fpages=str
End Function


``得到当前页面的地址
Function GetUrl()
    On Error Resume Next
Dim strTemp
If LCase(Request.ServerVariables("HTTPS")) = "off" Then
   strTemp = "http://"
Else
   strTemp = "https://"
End If
strTemp = strTemp & Request.ServerVariables("SERVER_NAME")
If Request.ServerVariables("SERVER_PORT") <> 80 Then strTemp = strTemp & ":" & Request.ServerVariables("SERVER_PORT")
    strTemp = strTemp & Request.ServerVariables("URL")
If Trim(Request.QueryString) <> "" Then strTemp = strTemp & "?" & Trim(Request.QueryString)
GetUrl = strTemp
End Function
%>
<% conn=openconn() %>
<%
Dim ID,zd1,zd2,zd3,zd4,zd5,Zd6
Page = SafeRequest("Page",1,1)
Page_Size = SafeRequest("Page_Size",1,10)
Set Rs = Server.CreateObject("Adodb.Recordset")
Sql = "Select ID,zd1,zd2,zd3,zd4,zd5,Zd6 From qwer Order by ID desc"
Rs.Open sql,conn,1,1
IF Not Rs.EOF Then 
Rs.PageSize = Page_Size
IF Page > Rs.Pagecount Then Page = Rs.Pagecount
Rs.AbsolutePage = page
For i=1 To Rs.PageSize
ID=Rs("ID")
zd1=Rs("zd1")
zd2=Rs("zd2")
zd3=Rs("zd3")
zd4=Rs("zd4")
zd5=Rs("zd5")
Zd6=Rs("Zd6")
    ``*****以下是您要添加代码的地方*****
    %>
<%=id%>

    <%
    ``*****以上是您要添加代码的地方*****
    Rs.MoveNext
    IF Rs.EOF Then 
      Exit For
    End IF
Next
End IF
Rs.Close
Set Rs = Nothing
%><%
Sql = "Select Count(*) From qwer "
Set Rs = Server.CreateObject("ADODB.Recordset")
Rs.Open Sql,Conn,1,1
If Not Rs.Eof Then
num = Rs(0)
End If
Rs.Close
Set Rs = Nothing
pagestr = Fpages("",num,page,page_size)
Response.Write pagestr

%>


所有代码都是工具生成,但是分页功能无法使用。

wangsdongwangsdong 2楼
wangsdong
发表于 2016-06-03 09:49:30 回顶端 
非常抱歉,今天才看到你的问题
wangsdongwangsdong 3楼
wangsdong
发表于 2016-06-03 09:54:29 回顶端 
怎么联系你?有QQ吗?我要远程调试你的代码
lxsanyuelxsanyue 4楼
lxsanyue
发表于 2016-06-06 08:01:10 回顶端 
qq32424193,测试环境win7x64+iis7.5。
wangsdongwangsdong 5楼
wangsdong
发表于 2016-06-06 13:31:53 回顶端 
<% conn=openconn() %>这行改成<% set conn=openconn() %>试试
wangsdongwangsdong 6楼
wangsdong
发表于 2016-06-06 13:38:26 回顶端 
提示什么错误
共1页 每页20条 页次:1/1
  • 首页
  • 上一页
  • 1
  • 下一页
  • 尾页

关于我们-广告合作-联系我们-积分规则-网站地图

Copyright(C)2013-2017版权所属asp编程网