1. 论坛系统升级为Xenforo,欢迎大家测试!
    排除公告

分页问题求教~~~

本帖由 落伍2005-09-05 发布。版面名称:后端开发

  1. 落伍

    落伍 New Member

    注册:
    2005-09-05
    帖子:
    26
    赞:
    0
    :p 问一个ASP的问题 查询出来分页时出错
    "&Request.form("v_index")&" 这个是由查询的单选项提交过来的....


    rs.open "select * from ebook where "&Request.form("v_index")&" like '%"&searchkey&"%' ",conn,1,1使用上面的查询语句时。
    在分页处理时。
    提供上面的查询语句。
    Microsoft OLE DB Provider for ODBC Drivers 错误 '80040e21'

    ODBC 驱动程序不支持所需的属性。


    分页的表示是:2.asp?page="&n&"


    一般的查询语句分页都通过了
    带这个 "&Request.form("v_index")&" 就出错。
    是啥原因?





    <%'开始分页
    Const MaxPerPage=2
    dim totalPut
    dim CurrentPage
    dim TotalPages
    dim j
    dim sql
    if Not isempty(request("page")) then
    currentPage=Cint(request("page"))
    else
    currentPage=1
    end if


    set rs=server.CreateObject("adodb.recordset")
    rs.open "select * from book where "&Request.form("v_index")&" like '%"&searchkey&"%' ",conn,1,1

    if rs.eof And rs.bof then
    Response.Write "<p align=center> 对不起,没有查讯到您需要的书!</p><br>"
    else
    totalPut=rs.recordcount
    if currentpage<1 then
    currentpage=1
    end if

    if (currentpage-1)*MaxPerPage>totalput then
    if (totalPut mod MaxPerPage)=0 then
    currentpage= totalPut \ MaxPerPage
    else
    currentpage= totalPut \ MaxPerPage + 1
    end if
    end if

    if currentPage=1 then
    showContent
    showpage totalput,MaxPerPage,"2.asp"
    else
    if (currentPage-1)*MaxPerPage<totalPut then
    rs.move (currentPage-1)*MaxPerPage
    dim bookmark
    bookmark=rs.bookmark
    showContent
    showpage totalput,MaxPerPage,“2.asp"
    else
    currentPage=1
    showContent
    showpage totalput,MaxPerPage,”2.asp"
    end if
    end if
    end if

    sub showContent
    dim i
    i=0
    %>
    <%do while not rs.eof%>



    题名:<%=rs("title")%> 题名2 :<%=rs("title2")%> 题名3:<%=rs("title3")%>






    <%i=i+1
    if i>=MaxPerPage then Exit Do
    rs.movenext
    loop
    rs.close
    set rs=nothing
    %>
    <%
    End Sub
    Function showpage(totalnumber,maxperpage,filename)
    Dim n
    If totalnumber Mod maxperpage=0 Then
    n= totalnumber \ maxperpage
    Else
    n= totalnumber \ maxperpage+1
    End If

    Response.Write "<form method=Post action="&filename&">"
    Response.Write "<p align='center' class='contents'> "
    If CurrentPage<2 Then
    Response.Write "<font class='contents'>首页 上一页</font> "
    Else
    Response.Write "<a href="&filename&"?page=1 class='contents'>首页</a> "
    Response.Write "<a href="&filename&"?page="&CurrentPage-1&" class='contents'>上一页</a> "
    End If

    If n-currentpage<1 Then
    Response.Write "<font class='contents'>下一页 尾页</font>"
    Else
    Response.Write "<a href="&filename&"?page="&(CurrentPage+1)&" class='contents'>"
    Response.Write "下一页</a> <a href="&filename&"?page="&n&" class='contents'>尾页</a>"
    End If
    Response.Write "<font class='contents'> 页次:</font><font class='contents'>"&CurrentPage&"</font>< ont class='contents'>/"&n&"页</font> "
    Response.Write "<font class='contents'> 共查讯到"&totalnumber&"种书 "
    Response.Write "<font class='contents'>转到:</font><input CLASS='wenbenkuang' type='text' name='page' size=2 maxlength=8 class=smallInput value="&currentpage&">"
    Response.Write " <input type='submit' CLASS='go-wenbenkuang' class='contents' value='GO' name='cndok'></form>"

    End Function
    %>






    上面就是分页的全过程在其它查询语句里可以用。。 可以查出结果来。
    但在翻页时就出错提示一楼的错误
     
  2. 小叶

    小叶 New Member

    注册:
    2005-09-04
    帖子:
    17,941
    赞:
    33
    PHP:
    <%set rs=server.CreateObject("ADODB.RecordSet")
    i=0
    sql
    ="select * from ebook where  year like '"&zyear&"%' order by ID desc"
    rs.open sql,connstr,1,1
    if rs.eof then  
    DY_LB
    ="<font color=red><b>没有记录</b></font>"
    Else

    '每页的条数
    const maxperpage=15           
    dim currentpage               
    rs.pagesize=maxperpage               
    currentpage=request.querystring("pageid")               
    if currentpage="" then               
    currentpage=1               
    elseif currentpage<1 then               
    currentpage=1               
    else               
    currentpage=clng(currentpage)               
        if currentpage > rs.pagecount then               
        currentpage=rs.pagecount               
        end if               
    end if               
                   
    if not isnumeric(currentpage) then               
    currentpage=1               
    end if               
    dim totalput,n               
    totalput=rs.recordcount               
    if totalput mod maxperpage=0 then               
    n=totalput\maxperpage               
    else               
    n=totalput\maxperpage+1               
    end if               
    if n=0 then               
    n=1               
    end if               
    rs.move(currentpage-1)*maxperpage

    i=0                                  
    do while not rs.eof  

    '
    读取记录
    title
    =rs("title")
    .....

        
    i=i+1                                                                                    
        rs
    .movenext                                                                                       
        loop                                                                                                              
        end 
    if                
    rs.close
    set rs
    =nothing
    conn
    .close
    set conn
    =nothing

    '###读取分页开始###
    DY_PAGE=DY_PAGE&"<table border=""0"" cellspacing=""1"" width=""100%"" class=""text""><tr>"       
    DY_PAGE=DY_PAGE&"<td width=""50%"">每页"&maxperpage&"条 共有订单:<font face=""arial"" color=""red"">"&totalput&"</font>个 <font face=""arial"" color=""red"">"&currentpage&"/"&n&"</font>页  </td>"                                                                                       
    DY_PAGE=DY_PAGE&"<td width=""32%""><div align=""right"">"
            k=currentpage                                                                                                         
         if k<>1 then                                                                                   
    DY_PAGE=DY_PAGE&"<a href=order.asp?pageid=1><font color=red>首页</font></a>&nbsp;"                                                                                                         
    DY_PAGE=DY_PAGE&"<a href=order.asp?pageid="&k-1&"><font color=red>上一页</font></a>&nbsp;"                                                                                                         
            else                                                                                     
    DY_PAGE=DY_PAGE&"<font color=#999966>首页&nbsp;上一页&nbsp;</font>"                                                                                                         
           end if                                                                                   
           if k<>n then                                                                                                        
    DY_PAGE=DY_PAGE&"<a href=order.asp?pageid="&k+1&"><font color=red>下一页</font></a>&nbsp;"                                                                                                         
    DY_PAGE=DY_PAGE&"<a href=order.asp?pageid="&n&"><font color=red>尾页</font></a>&nbsp;"                                                                                                         
           else                                                                                     
    DY_PAGE=DY_PAGE&"<font color=#999966>下一页&nbsp;尾页</font>"                                                                                                         
           end if                                                                                    
    DY_PAGE=DY_PAGE&"</div></td></tr></table> "
    %>
    '
    分页结束
     
  3. 不学无术

    不学无术 Ulysses 的元神

    注册:
    2005-08-31
    帖子:
    16,714
    赞:
    39
    分页后,无法通过 Request.Form 来获取 v_index 。你可以使用 Request("v_index") ,这样 Form 或者 QueryString 的内容都可以获取。

    另外,分页的时候似乎也没有传递该参数。
     
  4. 落伍

    落伍 New Member

    注册:
    2005-09-05
    帖子:
    26
    赞:
    0
    恩.没有传递参数.
    可以在我上面的分页代码里加上传送的参数嘛/./.

    回二楼的:
    你那上面发的查询是查询一个表里某个固定字段..
    我那代码.的字段不是固定的.. 是由用户选单选框来决定的!
    所以在这里就不太会分页了.
    我想在我
    Response.Write "下一页</a> <a href="&filename&"?page="&n&" class='contents'>尾页</a>"
    这里加一个传送参数的就应该可以分页了.

    我不会加.不怎么怎么加进去.
    希望能帮加一下呀:eek:hh:
     
  5. 落伍

    落伍 New Member

    注册:
    2005-09-05
    帖子:
    26
    赞:
    0
  6. 小叶

    小叶 New Member

    注册:
    2005-09-04
    帖子:
    17,941
    赞:
    33
    Response.Write "下一页</a> <a href="&filename&"?page="&n&"&string="&变量&" class='contents'>尾页</a>"
     
  7. 落伍

    落伍 New Member

    注册:
    2005-09-05
    帖子:
    26
    赞:
    0
    晕死。。
    能不能直接把我上面的代码变量放进去。。
    <a href="&filename&"?page="&n&"&i_index="&i_index&"&searchkey="&searchkey&" class='contents'>
    我自己写的没有用晕~
     
  8. 落伍

    落伍 New Member

    注册:
    2005-09-05
    帖子:
    26
    赞:
    0
    累死了。换了一种方法查询。。

    解决了。
    谢谢呀。辛苦了各位。