| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2505 人关注过本帖, 2 人收藏
标题:大量记录快速分页代码,SQL语句分页
只看楼主 加入收藏
zhangyao3287
Rank: 2
来 自:黑龙江省
等 级:论坛游民
威 望:2
帖 子:173
专家分:51
注 册:2008-5-25
结帖率:0
收藏(2)
 问题点数:0 回复次数:15 
大量记录快速分页代码,SQL语句分页
<%
Cardnumber = Conn.Execute("select count(*) as counts from [List_view]")("counts")
vPage = Cint(Request.QueryString("Page"))
vPageSize = 50
If Cardnumber mod vPageSize > 0 Then
vPgnum = Cint(Fix(Cardnumber/vPageSize) + 1)
Else
vPgnum = Cint(Cardnumber/vPageSize)
End If
If vPage = "" Or vPage < 1 Then vPage = 1
If vPage > vPgnum Then vPage = vPgnum
vPagecount = vPageSize*(vPage-1)
Set vRs = Server.CreateObject("ADODB.Recordset")
If vPage = 1 Then
Sql = "select top "&vPageSize&" id from [List_view] order by id"
Else
Sql = "select top "&vPageSize&" id from [List_view] where (id not in (select top "&vPagecount&" id from [List_view] order by id)) order by id"
End If
vRs.Open Sql,conn,1,1
  If vRs.Eof Then
    Response.Write("暂无数据~~~")
  Else
    Do While Not vRs.Eof
    Response.Write(""&vRs("id")&"<br />")
    vRs.MoveNext
    Loop
    vRs.close:Set vRs = Nothing
  End If

'---------------------分页开始------------------------
If Cardnumber > vPageSize Then

Response.Write "          <div id=""Main_ShowPage"">" & Chr(13)
if AllPage > vPgnum then
    AllPage = vPgnum
end if
   
if vPage - FrontPage < 1 then
    Start = 1
    sEnd = AllPage
elseif vPage + AllPage - FrontPage > vPgnum  then
    Start = vPgnum - AllPage + 1
    sEnd = vPgnum
else
    Start = vPage - FrontPage
    sEnd = vPage - FrontPage + AllPage - 1
end if

for i = Start to sEnd
if i = 1 then
    Url = "1"
else
    Url = i
end if
    if i = vPage then
        vPages = vPages & "<font color=""#ff0000""><b>["&i&"]</b></font> "
    else
        vPages = vPages & "<a href=""?Page="&Url&""">["&i&"]</a> "
    end if   
next

if vPage = 1 then
    Fpage = "首页"
    Lpage = "上一页"
else
    Fpage = "<a  href=""?Page=1"">首页</a>"
    Lpage = "<a  href=""?Page="&vPage - 1&""">上一页</a>"
end if

if vPage = vPgnum then
    Npage = "下一页"
    Rpage = "尾页"
else
    Npage = "<a  href=""?Page="&vPage + 1&""">下一页</a>"
    Rpage = "<a  href=""?Page="&vPgnum&""">尾页</a>"
end if

Response.Write "共"&Cardnumber&"条记录  页次:"&vPage&"/"&vPgnum&"页  "&Fpage&"  "&Lpage&"  "&vPages&"  "&Npage&"  "&Rpage&"  "
Response.Write "<select name=""page"" onChange=javascript:location.href=""?Page=""+document.all.page.options[document.all.page.selectedIndex].value+"""" size=""1"">"
for i = 1 to vPgnum
Response.Write "    <option value="""&i&""" "
if vPage = i then Response.Write "selected"
Response.Write ">第"&i&"页</option>"
next
Response.Write "</select>"
Response.Write "          </div>" & Chr(13)

End If
'---------------------分页结束------------------------
%>

[[it] 本帖最后由 zhangyao3287 于 2008-6-6 11:14 编辑 [/it]]
搜索更多相关主题的帖子: SQL 语句 记录 代码 
2008-06-06 09:00
zhangyao3287
Rank: 2
来 自:黑龙江省
等 级:论坛游民
威 望:2
帖 子:173
专家分:51
注 册:2008-5-25
收藏
得分:0 
没人给点意见吗?好歹我也打了好半天啊,郁闷了
2008-06-06 09:39
zhangjianghan
Rank: 1
等 级:新手上路
帖 子:43
专家分:0
注 册:2008-4-17
收藏
得分:0 
顶!!!!!
楼主,我把你的代码拿来试一下,数据库字段都已改成我数据库表的,但出现“ODBC 驱动程序不支持所需的属性”这种情况,怎么回事呢,是不是还要改什么?
2008-06-06 10:02
zhangyao3287
Rank: 2
来 自:黑龙江省
等 级:论坛游民
威 望:2
帖 子:173
专家分:51
注 册:2008-5-25
收藏
得分:0 
错误出在第几行呢?
Response.Write SQL
Response.End()
2008-06-06 10:04
zhangjianghan
Rank: 1
等 级:新手上路
帖 子:43
专家分:0
注 册:2008-4-17
收藏
得分:0 
楼主在线呀  你好!
/web/小组信息/oo.asp,行 11  vRs.Open Sql,conn,1,1
2008-06-06 10:14
zhangyao3287
Rank: 2
来 自:黑龙江省
等 级:论坛游民
威 望:2
帖 子:173
专家分:51
注 册:2008-5-25
收藏
得分:0 
Response.Write SQL
Response.End()
然后把SQL放在查询分析器里运行一下
你用的是什么数据库啊?
这样测试一下
If vPage = 1 Then
Sql = "select top "&vPageSize&" id from [List_view] order by id"
Else
Sql = "select top "&vPageSize&" id from [List_view] where (id not in (select top "&vPagecount&" id from [List_view] order by id)) order by id"
End If
2008-06-06 10:20
zhangjianghan
Rank: 1
等 级:新手上路
帖 子:43
专家分:0
注 册:2008-4-17
收藏
得分:0 
我用的是acc数据库
2008-06-06 10:22
zhangjianghan
Rank: 1
等 级:新手上路
帖 子:43
专家分:0
注 册:2008-4-17
收藏
得分:0 
<!-- #include file="date.asp" -->
<table>
<%
Cardnumber = Conn.Execute("select count(*) as counts from teacher")("counts")
vPage = Request.QueryString("Page")
If vPage = "" Or Clng(vPage) < 1 Then vPage = 1
vPageSize =9
vPagecount = vPageSize*(vPage-1)
Set vRs = Server.CreateObject("ADODB.Recordset")
Sql = "select top "&vPageSize&" tid from teacher where (tid not in (select top "&vPagecount&" tid from teacher order by tid)) order by tid"
vRs.Open Sql,conn,1,1
  If vRs.Eof Then
    Response.Write("暂无数据~~~")
  Else
    Do While Not vRs.Eof%>
            <tr>
      <td width="100"><%=vRs("suser")%></td>
      <td width="100"><%=vRs("sxh")%></td>
       <td width="100"><%=vRs("sname")%></td>
      <td width="100"><%=vRs("ssex")%></td>
       <td width="100"><%=vRs("jmobile")%></td>
       </tr>
   <% vRs.MoveNext
    Loop
    vRs.close:Set vRs = Nothing
  End If

'---------------------分页开始------------------------
If Cardnumber > vPageSize Then

Response.Write "          <div id=""Main_ShowPage"">" & Chr(13)
if AllPage > vPgnum then
    AllPage = vPgnum
end if
   
if vPage - FrontPage < 1 then
    Start = 1
    sEnd = AllPage
elseif vPage + AllPage - FrontPage > vPgnum  then
    Start = vPgnum - AllPage + 1
    sEnd = vPgnum
else
    Start = vPage - FrontPage
    sEnd = vPage - FrontPage + AllPage - 1
end if

for i = Start to sEnd
if i = 1 then
    Url = "1"
else
    Url = i
end if
    if i = vPage then
        vPages = vPages & "<font color=""#ff0000""><b>["&i&"]</b></font> "
    else
        vPages = vPages & "<a href=""?Page="&Url&""">["&i&"]</a> "
    end if   
next

if vPage = 1 then
    Fpage = "首页"
    Lpage = "上一页"
else
    Fpage = "<a  href=""?Page=1"">首页</a>"
    Lpage = "<a  href=""?Page="&vPage - 1&""">上一页</a>"
end if

if vPage = vPgnum then
    Npage = "下一页"
    Rpage = "尾页"
else
    Npage = "<a  href=""?Page="&vPage + 1&""">下一页</a>"
    Rpage = "<a  href=""?Page="&vPgnum&""">尾页</a>"
end if

Response.Write "共"&Cardnumber&"条记录  页次:"&vPage&"/"&vPgnum&"页  "&Fpage&"  "&Lpage&"  "&vPages&"  "&Npage&"  "&Rpage&"  "
Response.Write "<select name=""page"" onChange=javascript:location.href=""?Page=""+document.all.page.options[document.all.page.selectedIndex].value+"""" size=""1"">"
for i = 1 to vPgnum
Response.Write "    <option value="""&i&""" "
if vPage = i then Response.Write "selected"
Response.Write ">第"&i&"页</option>"
next
Response.Write "</select>"
Response.Write "          </div>" & Chr(13)

End If
'---------------------分页结束------------------------
%>
</table>

这是我改以后的代码 ,你看看!!1
2008-06-06 10:26
zhangyao3287
Rank: 2
来 自:黑龙江省
等 级:论坛游民
威 望:2
帖 子:173
专家分:51
注 册:2008-5-25
收藏
得分:0 
access数据查询不支持 select top 0 * from
所以当vPage=1的时候多写一个SQL语句就可以了

If vPage = 1 Then
Sql = "select top "&vPageSize&" id from [List_view] order by id"
Else
Sql = "select top "&vPageSize&" id from [List_view] where (id not in (select top "&vPagecount&" id from [List_view] order by id)) order by id"
End If
2008-06-06 10:32
zhangjianghan
Rank: 1
等 级:新手上路
帖 子:43
专家分:0
注 册:2008-4-17
收藏
得分:0 
If Cardnumber > vPageSize Then

Response.Write "          <div id=""Main_ShowPage"">" & Chr(13)
if AllPage > vPgnum then
    AllPage = vPgnum
end if
   
if vPage - FrontPage < 1 then
    Start = 1
    sEnd = AllPage
elseif vPage + AllPage - FrontPage > vPgnum  then
    Start = vPgnum - AllPage + 1
    sEnd = vPgnum
else
    Start = vPage - FrontPage
    sEnd = vPage - FrontPage + AllPage - 1
end if

for i = Start to sEnd
if i = 1 then
    Url = "1"
else
    Url = i
end if
    if i = vPage then
        vPages = vPages & "<font color=""#ff0000""><b>["&i&"]</b></font> "
    else
        vPages = vPages & "<a href=oo.asp?Page="&Url&""">["&i&"]</a> "
    end if   
next

if vPage = 1 then
    Fpage = "首页"
    Lpage = "上一页"
else
    Fpage = "<a  href=oo.asp?Page=1"">首页</a>"
    Lpage = "<a  href=oo.asp?Page="&vPage - 1&""">上一页</a>"
end if

if vPage = vPgnum then
    Npage = "下一页"
    Rpage = "尾页"
else
    Npage = "<a  href=oo.asp?Page="&vPage + 1&""">下一页</a>"
    Rpage = "<a  href=oo.asp?Page="&vPgnum&""">尾页</a>"
end if

Response.Write "共"&Cardnumber&"条记录  页次:"&vPage&"/"&vPgnum&"页  "&Fpage&"  "&Lpage&"  "&vPages&"  "&Npage&"  "&Rpage&"  "
Response.Write "<select name=""page"" onChange=javascript:location.href=oo.asp?Page=""+document.all.page.options[document.all.page.selectedIndex].value+"""" size=""1"">"
for i = 1 to vPgnum
Response.Write "    <option value="""&i&""" "
if vPage = i then Response.Write "selected"
Response.Write ">第"&i&"页</option>"
next
Response.Write "</select>"
Response.Write "          </div>" & Chr(13)

End If

楼主应该怎么改,已经显示出来,但没出现下拉框,点击下一页就出错,这个页面是oo.asp
2008-06-06 11:01
快速回复:大量记录快速分页代码,SQL语句分页
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025975 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved