| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1377 人关注过本帖
标题:自已写的一个分页函数;贴出来,大家给PP
取消只看楼主 加入收藏
无根泉
Rank: 2
等 级:新手上路
威 望:4
帖 子:853
专家分:0
注 册:2004-11-4
收藏
 问题点数:0 回复次数:6 
自已写的一个分页函数;贴出来,大家给PP

自已写的一个分页函数;贴出来,大家给PP function showpage(table,size,page,url) set rst=server.CreateObject("adodb.recordset") sql="select count(*) from "&table&" " rst.open sql,conn,3,2 cot=int(rst(0)/size) ca=rst(0) mod size if ca<>0 then cot=cot+1 else cot=cot end if response.Write"共"&rst(0)&"条&nbsp;每页"&size&"条&nbsp;页次:"&page&"/"&cot&"&nbsp;" if page=1 then response.Write "[首页]&nbsp;[上页]&nbsp;" else response.Write"[<a href="&url&"?page=1>首页</a>]&nbsp;[<a href="&url&"?page="&page-1&">上页</a>]&nbsp;" end if if page=cot then response.Write "[下页]&nbsp;[尾页]&nbsp;" else response.Write"[<a href="&url&"?page="&page+1&">下页</a>]&nbsp;[<a href="&url&"?page="&cot&">尾页</a>]&nbsp;" end if response.Write"<select name='page' onchange='selected()'>" for i=1 to cot response.Write"<option value='"&i&"'" if i=page then response.Write "selected" response.Write">"&i&"</option>" next response.Write"</select>"

response.Write"<script>" response.Write"function selected(){" response.Write"var x=document.all.page.options[document.all.page.selectedIndex].value;" response.Write"window.location='"&url&"?page='+x;" response.Write"}</script>" rst.close set rst=nothing end function

搜索更多相关主题的帖子: 页函数 cot rst 
2005-04-03 09:48
无根泉
Rank: 2
等 级:新手上路
威 望:4
帖 子:853
专家分:0
注 册:2004-11-4
收藏
得分:0 
在这边再做一下修改,就可以支持带参数的分页了, 去掉分页里的? 如果window.location='"&url&"?page='+x;改为window.location='"&url&"page='+x; 调用是 call showpage("表名",每页的显示的条数,page,"index.asp?action=look&id="&id&"&") 这样就可以了, 或者 const table="表名" const size="每页的条数" call showpage(table,size,page,"index.asp?")

我很菜,但我很努力!
2005-04-04 09:14
无根泉
Rank: 2
等 级:新手上路
威 望:4
帖 子:853
专家分:0
注 册:2004-11-4
收藏
得分:0 
还是删了吧,要不在这也是浪费资源呀,
没有人光顾呀,

我很菜,但我很努力!
2005-04-06 08:29
无根泉
Rank: 2
等 级:新手上路
威 望:4
帖 子:853
专家分:0
注 册:2004-11-4
收藏
得分:0 

又改了一下, function showpage(cnt,size,page,url)

cot=int(cnt/size) ca=cnt mod size if ca<>0 then cot=cot+1 else cot=cot end if response.Write"共"&cnt&"条&nbsp;每页"&size&"条&nbsp;页次:"&page&"/"&cot&"&nbsp;" if page=1 then response.Write "[首页]&nbsp;[上页]&nbsp;" else response.Write"[<a href="&url&"page=1>首页</a>]&nbsp;[<a href="&url&"page="&page-1&">上页</a>]&nbsp;" end if if page=cot then response.Write "[下页]&nbsp;[尾页]&nbsp;" else response.Write"[<a href="&url&"page="&page+1&">下页</a>]&nbsp;[<a href="&url&"page="&cot&">尾页</a>]&nbsp;" end if response.Write"<select name='page' onchange='selected()'>" for i=1 to cot response.Write"<option value='"&i&"'" if i=page then response.Write "selected" response.Write">"&i&"</option>" next response.Write"</select>"

response.Write"<script>" response.Write"function selected(){" response.Write"var x=document.all.page.options[document.all.page.selectedIndex].value;" response.Write"window.location='"&url&"page='+x;" response.Write"}</script>"

end function 以下是调用: page=request.QueryString("page") if page="" then page=1 if len(page)>6 then page=1 if not isnumeric(page) then page=1 page=clng(page) set rs=server.CreateObject("adodb.recordset") sql="select * from smxx" rs.pagesize=50 rs.open sql,conn,3,2 if rs.eof then response.Write "当前没有记录!" else i=0 if page>rs.pagecount then page=rs.pagecount rs.absolutepage=page do while not rs.eof and i<rs.pagesize response.Write rs(1)&"<br>" i=i+1 rs.movenext loop%> <div align="center"><% call showpage(rs.recordcount,rs.pagesize,page,"untitled0.asp?") %></div> <%end if%>


我很菜,但我很努力!
2005-04-18 08:06
无根泉
Rank: 2
等 级:新手上路
威 望:4
帖 子:853
专家分:0
注 册:2004-11-4
收藏
得分:0 
老大。果然是老大,

服了!!!!!

我很菜,但我很努力!
2005-04-18 10:00
无根泉
Rank: 2
等 级:新手上路
威 望:4
帖 子:853
专家分:0
注 册:2004-11-4
收藏
得分:0 
以下是引用griefforyou在2005-4-18 9:10:27的发言:

'不使用Rs.AbsolutePage方法的分页函数 '可参考我的Blog中:ASP构造大数据量的分页SQL语句。 Function GetPageSQL(tblName,fldName,fldList,PageSize,PageIndex,OrderType,strWhere) Dim strTemp,strSQL,strOrder

'根据排序方式生成相关代码(缺省降序) if OrderType=1 then strTemp=">(select max([" & fldName & "])" strOrder=" order by [" & fldName & "] asc" else strTemp="<(select min([" & fldName & "])" strOrder=" order by [" & fldName & "] desc" end if '若是第1页则无须复杂的语句 if PageIndex=1 then strTemp="" if strWhere<>"" then strTmp = " where " + strWhere end if strSQL = "select top " & PageSize & fldList & " from [" & tblName & "]" & strTmp & strOrder else '若不是第1页,构造SQL语句 strSQL="select top " & PageSize & fldList & " from [" & tblName & "] where [" & fldName & "]" & strTemp & _ " from (select top " & (PageIndex-1)*PageSize & " [" & fldName & "] from [" & tblName & "]" if strWhere<>"" then strSQL=strSQL & " where " & strWhere end if strSQL=strSQL & strOrder & ") as tblTemp)" if strWhere<>"" then strSQL=strSQL & " And " & strWhere end if strSQL=strSQL & strOrder end if GetPageSQL=strSQL '返回SQL语句 End Function

我觉得可以改为这样,不知老大意下如何? function show(table,sql,size,page,fname) page=request.QueryString("page") if page="" then page=1 if page=1 then sql="select top "&size&" * from "&table&" " else sql="select top "&size&" * from "&table&" where("&fname&" not in (select top "&size*(page-1)&" "&fname&" from "&table&"))" end if show=sql end function %>

[此贴子已经被作者于2005-4-18 10:41:43编辑过]


我很菜,但我很努力!
2005-04-18 10:39
无根泉
Rank: 2
等 级:新手上路
威 望:4
帖 子:853
专家分:0
注 册:2004-11-4
收藏
得分:0 
是呀是呀,

还是老大厉害,

我很菜,但我很努力!
2005-04-22 21:45
快速回复:自已写的一个分页函数;贴出来,大家给PP
数据加载中...
 
   



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

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