叶子asp分页类
程序员文章站
2022-03-25 20:25:02
名称: 叶子asp分页类 name: showopage(vbs class) rcsfile: readme.txt revisi...
名称: 叶子asp分页类
name: showopage(vbs class)
rcsfile: readme.txt
revision: 0.12.20051114.f
author: yehe(叶子)
released: 2005-11-14 09:40:13
descript: asp分页类,支持access/mssql/mysql/sqlite
contact: qq:311673 msn:myehe@msn.com gt:mmyehe@gmail.com
website: http://www.yehe.org http://www.showo.com
------------------------------------------------
licenses:
本程序遵循gpl协议.
协议原文地址:http://www.gnu.org/licenses/licenses.cn.html#gpl
------------------------------------------------
thanks:
可洛: 感谢mssql分页核心部分
arbiter: 感谢部分分页思路
才子: 感谢推广
foxty: 感谢分页思路
------------------------------------------------
install:
1.具体调用方法可以看demo的asp文档.
2.mssql存储过程版的请先执行sp_util_page.sql文件添加存储过程.
3.sp调用方法:
exec sp_util_page 440000,4,10,''mid'',''mid,ip1,ip2,country,city'',''tbtemppage'',''1=1'',''mid asc''
记录条数(已有值:序外部赋值,0执行count),当前页数,每页记录数,主键,字段,表,条件(不需要where),排序(不需要order by,需要asc和desc字符)
如果不按主键排序,则排序赋值里面不能出现主键字符.
------------------------------------------------
release:
0.12
1.取text字段类型bug修正
2.存储过程bug修正
3.代码修正
0.11
1.存储过程加了非主键排序下的分页
2.去掉了mssql的非存储过程版分页
0.10:
1.条件简化
2.存储过程优化
0.09:
1.排序判断部分优化
0.08:
1.vbs bug修正
0.07:
1.bug修正,包括vbs类和js
0.06beta:
1.js浏览器兼容优化
2.类几个函数的bug修正
0.05beta:
1.全面代码优化,mysql/sqlite支持
2.参数输入方式修改
0.04beta:
1.做到调用代码一样适应多种数据库集成分页
2.js去掉了表单,支持静态提交
3.加上了存储过程
0.03beta:
1.公开发布的显示为0.02,其实为0.03,分为ac版类,mssql版类发布
2.js的bug修正
3.写成了类,进一步方便调用
0.02beta:
1.加上对mssql的支持
2.封装成了函数版,方便调用
3.js文件的优化
0.01beta:
1.没有写成函数,只是找到了比较快的ac分页方法
2.分页样式用js显示
------------------------------------------------
file:
db/ip.mdb access测试数据库
db/ip mssql备份测试数据库
cls_vbspage.asp 分页类
cls_jspage.js js分页样式
sp_util_page.sql mssql存储过程
demoac.asp ac分页调用示范
demomssql.asp mssql调用示范
demomssql_sp.asp mssql存储过程调用示范
cls_vbspage.asp
<%
class cls_vbspage
private oconn ''连接对象
private ipagesize ''每页记录数
private spagename ''地址栏页数参数名
private sdbtype
''数据库类型,ac为access,mssql为sql server2000存储过程版,mysql为mysql,pgsql为postgresql
private irectype ''记录总数(>0为另外取值再赋予或者固定值,0执行count设置存cookies,-1执行count不设置cookies)
private sjsurl ''cls_jspage.js的路径
private sfield ''字段名
private stable ''表名
private scondition ''条件,不需要where
private sorderby ''排序,不需要order by,需要asc或者desc
private spkey ''主键,必写
private ireccount
''================================================================
'' class_initialize 类的初始化
''================================================================
private sub class_initialize
ipagesize=10
spagename="page"
sdbtype="ac"
irectype=0
sjsurl=""
sfield=" * "
end sub
''================================================================
'' conn 得到数据库连接对象
''================================================================
public property set conn(byref value)
set oconn=value
end property
''================================================================
'' pagesize 设置每一页记录条数,默认10记录
''================================================================
public property let pagesize(byval intpagesize)
ipagesize=checknum(intpagesize,0,0,ipagesize,0)
end property
''================================================================
'' pagename 地址栏页数参数名
''================================================================
public property let pagename(byval strpagename)
spagename=iif(len(strpagename)<1,spagename,strpagename)
end property
''================================================================
'' dbtype 得到数据库类型
''================================================================
public property let dbtype(byval strdbtype)
sdbtype=ucase(iif(len(strdbtype)<1,sdbtype,strdbtype))
end property
''================================================================
'' rectype 取记录总数(>0为赋值或者固定值,0执行count设置存cookies,-1执行count不设置cookies适用于搜索)
''================================================================
public property let rectype(byval intrectype)
irectype=checknum(intrectype,0,0,irectype,0)
end property
''================================================================
'' jsurl 取得cls_jspage.js的路径
''================================================================
public property let jsurl(byval strjsurl)
sjsurl=strjsurl
end property
''================================================================
'' pkey 取得主键
''================================================================
public property let pkey(byval strpkey)
spkey=strpkey
end property
''================================================================
'' field 取得字段名
''================================================================
public property let field(byval strfield)
sfield=iif(len(strfield)<1,sfield,strfield)
end property
''================================================================
'' table 取得表名
''================================================================
public property let table(byval strtable)
stable=strtable
end property
''================================================================
'' condition 取得条件
''================================================================
public property let condition(byval strcondition)
s=strcondition
scondition=iif(len(s)>2," where "&s,"")
end property
''================================================================
'' orderby 取得排序
''================================================================
public property let orderby(byval strorderby)
s=strorderby
sorderby=iif(len(s)>4," order by "&s,"")
end property
''================================================================
'' reccount 修正记录总数
''================================================================
public property get reccount()
if irectype>0 then
i=irectype
elseif irectype=0 then
i=checknum(request.cookies("showopage")(spagename),1,0,0,0)
s=trim(request.cookies("showopage")("scond"))
if i=0 or scondition<>s then
i=oconn.execute("select count("&spkey&") from "&stable&" "&scondition,0,1)(0)
response.cookies("showopage")(spagename)=i
response.cookies("showopage")("scond")=scondition
end if
else
i=oconn.execute("select count("&spkey&") from "&stable&" "&scondition,0,1)(0)
end if
ireccount=i
reccount=i
end property
''================================================================
'' resultset 返回分页后的记录集
''================================================================
public property get resultset()
s=null
''记录总数
i=ireccount
''当前页
if i>0 then
ipagecount=abs(int(-abs(i/ipagesize)))''页数
ipagecurr=checknum(request.querystring(spagename),1,1,1,ipagecount)''当前页
select case sdbtype
case "mssql" ''sqlserver2000数据库存储过程版
set rs=server.createobject("adodb.recordset")
set cm=server.createobject("adodb.command")
cm.commandtype=4
cm.activeconnection=oconn
cm.commandtext="sp_util_page"
cm.parameters(1)=i
cm.parameters(2)=ipagecurr
cm.parameters(3)=ipagesize
cm.parameters(4)=spkey
cm.parameters(5)=sfield
cm.parameters(6)=stable
cm.parameters(7)=replace(scondition," where ","")
cm.parameters(8)=replace(sorderby," order by ","")
rs.cursorlocation=3
rs.locktype=1
rs.open cm
case "mysql" ''mysql数据库
resultset_sql="select "&sfield&" from "&stable&" "&scondition&" "&sorderby&" limit "&(ipagecurr-1)*ipagesize&","&ipagesize
set rs=oconn.execute(resultset_sql)
case else ''其他情况按最原始的方法处理(ac同理)
set rs = server.createobject ("adodb.recordset")
resultset_sql="select "&sfield&" from "&stable&" "&scondition&" "&sorderby
rs.open resultset_sql,oconn,1,1,&h0001
rs.absoluteposition=(ipagecurr-1)*ipagesize+1
end select
s=rs.getrows(ipagesize)
rs.close
set rs=nothing
end if
resultset=s
end property
''================================================================
'' class_terminate 类注销
''================================================================
private sub class_terminate()
if isobject(oconn) then oconn.close:set oconn=nothing
end sub
''================================================================
'' 输入:检查字符,是否有最小值,是否有最大值,最小值(默认数字),最大值
''================================================================
private function checknum(byval strstr,byval blnmin,byval blnmax,byval intmin,byval intmax)
dim i,s,imi,ima
s=left(trim(""&strstr),32):imi=intmin:ima=intmax
if isnumeric(s) then
i=cdbl(s)
i=iif(blnmin=1 and i<imi,imi,i)
i=iif(blnmax=1 and i>ima,ima,i)
else
i=imi
end if
checknum=i
end function
''================================================================
'' 输入:简化条件判断
''================================================================
private function iif(byval blnbool,byval strstr1,byval strstr2)
dim s
if blnbool then
s=strstr1
else
s=strstr2
end if
iif=s
end function
''================================================================
'' 上下页部分
''================================================================
public sub showpage()%>
<script language="javascript" type="text/javascript" src="<%=sjsurl%>cls_jspage.js"></script>
<script language="javascript" type="text/javascript">
var s= new cls_jspage(<%=ireccount%>,<%=ipagesize%>,3,"s");
s.setpagese("<%=spagename%>=","");
s.setpageinput("<%=spagename%>");
s.seturl("");
s.setpagefrist("首页","<<");
s.setpageprev("上页","<");
s.setpagenext("下页",">");
s.setpagelast("尾页",">>");
s.setpagetext("[{$pagenum}]","第{$pagenum}页");
s.setpagetextf(" {$pagetextf} "," {$pagetextf} ");
s.setpageselect("{$pagenum}","第{$pagenum}页");
s.setpagecss("","","");
s.sethtml("共{$reccount}记录 页次{$page}/{$pagecount} 每页{$pagesize}条 {$pagefrist} {$pageprev} {$pagetext} {$pagenext} {$pagelast} {$pageinput} {$pageselect}");
s.write();
</script>
<%end sub
end class%>
cls_jspage.js
/**
*=================================================================
*name: 叶子js分页样式(showopage style with js)
*rcsfile: cls_jspage.js
*revision: 0.09
*author: yehe(叶子)
*released: 2005-05-12 23:00:15
*description: js分页样式,显示上一页下一页的翻页结果
*contact: qq:311673,msn:myehe@msn.com
*website: http://www.yehe.org,http://www.showo.com
*=================================================================
*/
function cls_jspage(ireccount,ipagesize,ipagenum,sname){
this.irc=this.formatnum(ireccount,1,0,0,0);//总记录条数
this.ips=this.formatnum(ipagesize,1,0,1,0);//每页记录数目
this.ipn=this.formatnum(ipagenum,0,0,0,0);//显示的前后页数,0为显示所有,负数为这么多页面一个跳转
this.sn=sname;//实例对象名
this.stpage="{$page}";//页数
this.stpagecount="{$pagecount}";//总页数
this.streccount="{$reccount}";//总记录数
this.stpagesize="{$pagesize}";//每页记录数
this.stpagefrist="{$pagefrist}";//首页
this.stpageprev="{$pageprev}";//上页
this.stpagenext="{$pagenext}";//下页
this.stpagelast="{$pagelast}";//尾页
this.stpagetext="{$pagetext}";//数字跳转
this.stpagetextf="{$pagetextf}";//数字跳转框架
this.stpageinput="{$pageinput}";//输入框跳转
this.stpageselect="{$pageselect}";//下拉菜单跳转
this.stpagenum="{$pagenum}";//数字页数
this.ipc=this.getpagecount();//得到页数
}
//输入 页数开始值,结尾值
cls_jspage.prototype.setpagese=function(spagestart,spageend){
var sps=spagestart,spe=spageend;
this.sps=(sps.length>0)?sps:"page=";
this.spe=(spe.length>0)?spe:"";
}
//输入 网址
cls_jspage.prototype.seturl=function(surl){
var s=surl;
this.url=(s.length>0)?s:""+document.location;
}
//输入 输入框&下拉框name值
cls_jspage.prototype.setpageinput=function(spageinput){
var spi=spageinput;
this.spi=(spi.length>0)?spi:"page";
}
//输入 语言 首页(disable,enale)
cls_jspage.prototype.setpagefrist=function(sdis,sen){
this.pf_d=sdis;
this.pf_e=sen;
}
//输入 语言 上页
cls_jspage.prototype.setpageprev=function(sdis,sen){
this.pp_d=sdis;
this.pp_e=sen;
}
//输入 语言 下页
cls_jspage.prototype.setpagenext=function(sdis,sen){
this.pn_d=sdis;
this.pn_e=sen;
}
//输入 语言 尾页
cls_jspage.prototype.setpagelast=function(sdis,sen){
this.pl_d=sdis;
this.pl_e=sen;
}
//输入 语言 数字跳转
cls_jspage.prototype.setpagetext=function(sdis,sen){
this.pt_d=sdis;//"[{$pagenum}]"
this.pt_e=sen;//"第{$pagenum}页"
}
//输入 语言 数字跳转外围模板
cls_jspage.prototype.setpagetextf=function(sdis,sen){
this.ptf_d=sdis;//" {$pagetextf} "
this.ptf_e=sen;//" {$pagetextf} "
}
//输入 语言 下拉菜单跳转
cls_jspage.prototype.setpageselect=function(sdis,sen){
this.ps_d=sdis;//"[{$pagenum}]"
this.ps_e=sen;//"第{$pagenum}页"
}
//输入 css
cls_jspage.prototype.setpagecss=function(scsspagetext,scsspageinput,scsspageselect){
this.cpt=scsspagetext;//数字跳转css
this.cpi=scsspageinput;//输入框跳转css
this.cps=scsspageselect;//下拉菜单跳转css
}
//输入 html模板
cls_jspage.prototype.sethtml=function(shtml){
this.html=shtml;//html模板
}
//计算页数
cls_jspage.prototype.getpagecount=function(){
var irc=this.irc,ips=this.ips;
var i=(irc%ips==0)?(irc/ips):(this.formatnum((irc/ips),1,0,0,0)+1);
return (i);
}
//取得模板页数和当前页数
cls_jspage.prototype.geturl=function(itype){
var s=this.url,sps=this.sps,spe=this.spe,stp=this.stpage,ipc=this.ipc;
var it=itype,i;
if (s.indexof(sps)==-1) {
s+=((s.indexof("?")==-1)?"?":"&")+sps+stp;
i=1;
}
else {
sreg="(\\s.*)"+this.formatreg(sps)+"(\\d*)"+this.formatreg(spe)+"(\\s.*|\\s*)";
var spindex=this.reg(s,sreg,"$3");
s=s.replace(sps+spindex+spe,sps+stp+spe);
i=this.formatnum(spindex,1,1,0,ipc);
}
s=this.reg(s,"(&+)","&");
s=this.reg(s,"(\\?&)","?");
return (it==0?s:i);
}
//页面跳转
cls_jspage.prototype.pagejump=function(){
var spl,spv,sp;
var su=this.geturl(0),ipi=this.geturl(1);
var spi=this.spi,stp=this.stpage,ipc=this.ipc;
spl=document.getelementsbyname(spi).length;
for (var i=0;i<spl;i++) {
spv=document.getelementsbyname(spi)[i].value;
sp=this.formatnum(spv,1,1,0,ipc);
if (sp>0) {
location.href=su.replace(stp,sp);
break;
}
}
}
//输出
cls_jspage.prototype.write=function(){
var su=this.geturl(0),ipi=this.geturl(1);
var sn=this.sn,spi=this.spi;
var ipc=this.ipc,ipn=this.ipn;;
var irc=this.irc,ips=this.ips;
var pf_d=this.pf_d,pf_e=this.pf_e;
var pp_d=this.pp_d,pp_e=this.pp_e;
var pn_d=this.pn_d,pn_e=this.pn_e;
var pl_d=this.pl_d,pl_e=this.pl_e;
var pt_d=this.pt_d,pt_e=this.pt_e;
var ptf_d=this.ptf_d,ptf_e=this.ptf_e;
var ps_d=this.ps_d,ps_e=this.ps_e;
var cpt=this.cpt,cpi=this.cpi;
var cps=this.cps,ipn=this.ipn;
var s=this.html;
stpage=this.stpage;
stpagecount=this.stpagecount;
streccount=this.streccount;
stpagesize=this.stpagesize;
stpfrist=this.stpagefrist;
stpprev=this.stpageprev;
stpnext=this.stpagenext;
stplast=this.stpagelast;
stptext=this.stpagetext;
stptextf=this.stpagetextf;
stpinput=this.stpageinput;
stpselect=this.stpageselect;
stpagenum=this.stpagenum;
var prevp=this.formatnum((ipi-1),1,1,1,ipc),nextp=this.formatnum((ipi+1),1,1,1,ipc);
var fu,pu,nu,lu;
var s1="<span class=\""+cpt+"\"><a href=\"",s2="\">",s3="</a></span>";
var s4="<span class=\""+cpt+"\">",s5="</span>";
if (ipi<=1&&ipc<=1) {
fu=s4+pf_d+s5;
pu=s4+pp_d+s5;
nu=s4+pn_d+s5;
lu=s4+pl_d+s5;
}
else if (ipi==1&&ipc>1) {
fu=s4+pf_d+s5;
pu=s4+pp_d+s5;
nu=s1+su.replace(stpage,nextp)+s2+pn_e+s3;
lu=s1+su.replace(stpage,ipc)+s2+pl_e+s3;
}
else if (ipi==ipc) {
fu=s1+su.replace(stpage,1)+s2+pf_e+s3;
pu=s1+su.replace(stpage,prevp)+s2+pp_e+s3;
nu=s4+pn_d+s5;
lu=s4+pl_d+s5;
}
else {
fu=s1+su.replace(stpage,1)+s2+pf_e+s3;
pu=s1+su.replace(stpage,prevp)+s2+pp_e+s3;
nu=s1+su.replace(stpage,nextp)+s2+pn_e+s3;
lu=s1+su.replace(stpage,ipc)+s2+pl_e+s3;
}
var pagestart,pageend;
if (ipn<0) {
ipn=math.abs(ipn);
pagestart=(ipi%ipn==0)?(ipi/ipn):(this.formatnum((ipi/ipn),1,0,0,0));
pagestart=(pagestart*ipn==ipi)?((pagestart-1)*ipn+1):(pagestart*ipn+1);
pageend=this.formatnum(pagestart+ipn,0,1,0,ipc)
}
else if (ipn==0) {
pagestart=1;
pageend=ipc;
}
else {
pagestart=this.formatnum((ipi-ipn),1,0,1,0);
pageend=this.formatnum((pagestart+ipn*2),0,1,0,ipc);
pagestart=(pageend==ipc)?this.formatnum((pageend-ipn*2),1,0,1,0):pagestart;
}
var pselect="",ptext="",pinput="",p;
if (ipc>=1) {
pselect="<select class=\""+cps+"\" name=\""+spi+"\" onchange=\""+sn+".pagejump()\">";
pinput="<input class=\""+cpi+"\" type=\"text\" name=\""+spi+"\" size=\"5\" maxlength=\"10\" onkeydown=\"if (event.keycode==13) "+sn+".pagejump()\">";
for (var i=pagestart;i<=pageend;i++) {
if (i!=ipi) {
p=s1+su.replace(stpage,i)+s2+pt_e.replace(stpagenum,i)+s3;
ptext+=ptf_e.replace(stptextf,p);
pselect+="<option value=\""+i+"\">"+ps_e.replace(stpagenum,i)+"</option>";
}
else {
p=s4+pt_d.replace(stpagenum,i)+s5;
ptext+=ptf_d.replace(stptextf,p);
pselect+="<option selected=\"selected\">"+ps_d.replace(stpagenum,i)+"</option>";
}
}
pselect+="</select>";
}
s=s.replace(stpage,ipi);
s=s.replace(stpagecount,ipc);
s=s.replace(streccount,irc);
s=s.replace(stpagesize,ips);
s=s.replace(stpfrist,fu);
s=s.replace(stpprev,pu);
s=s.replace(stpnext,nu);
s=s.replace(stplast,lu);
s=s.replace(stptext,ptext);
s=s.replace(stpinput,pinput);
s=s.replace(stpselect,pselect);
document.write (s);
}
//输入:欲格式化字符,是否有最小值(0表示没有,1表示有),是否有最大值,最小值(默认值),最大值
cls_jspage.prototype.formatnum=function(snum,bmin,bmax,iminnum,imaxnum){
var i,in,sn=""+snum,imin=iminnum,imax=imaxnum;
if (sn.length>0) {
in=parseint(sn,10);
i=(isnan(in))?imin:in;
i=(i<imin&&bmin==1)?imin:i;
i=(i>imax&&bmax==1)?imax:i;
}
else {
i=imin;
}
return (i);
}
//输入:欲正则字符,正则表达式,替换后字符
cls_jspage.prototype.reg=function(sstr,sreg,sre){
var s="",ss=sstr,sr=sreg,sre=sre;
if ((ss.length>0)&&(sr.length>0)) {
eval("re=/"+sr+"/gim;");
s=ss.replace(re,sre);
}
return (s);
}
//格式化正则中的特殊字符
cls_jspage.prototype.formatreg=function(sreg){
var s="",sr=sreg;
var sf=new array ("/",".","+","[","]","{","}","$","^","?","*");
if (sr.length>0) {
for (var i=0;i<=sf.length;i++) {
sr=sr.replace(sf[i],"\\"+sf[i]);
}
s="("+sr+")";
}
return (s);
}
demoac.asp
<%@language="vbscript" codepage="936"%>
<!--#include file="cls_vbspage.asp"-->
<%
''-----------------------------------------------------------------------------------------------
on error resume next
dim startime,endtime
''统计执行时间
startime=timer()
''连接数据库
dim db,conn,rs
db = "provider=microsoft.jet.oledb.4.0;data source=" & server.mappath("db/ip.mdb")
set conn = server.createobject("adodb.connection")
conn.open db
''-----------------------------------------------------------------------------------------------
%>
<html>
<head>
<title>叶子asp分页类-access调用示范</title>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
table { font-size: 12px}
a { font-size: 12px; color: #000000; text-decoration: none}
-->
</style>
</head>
<body bgcolor="#ffffff" text="#000000">
<table width="760" border="0" cellspacing="2" cellpadding="2" align="center" height="30">
<tr>
<td> </td>
</tr>
</table>
<table width="760" border="1" cellspacing="0" cellpadding="4" align="center" bordercolordark="#ffffff" bordercolorlight="#cccccc">
<tr align="center">
<td width="20">id</td>
<td>标题</td>
<td>内容(显示前20个字)</td>
<td>时间</td>
</tr>
<%
dim ors
set ors=new cls_vbspage ''创建对象
set ors.conn=conn ''得到数据库连接对象
with ors
.pagesize=13 ''每页记录条数
.pagename="pages" ''cookies名称
.dbtype="ac"
''数据库类型,ac为access,mssql为sqlserver2000存储过程版,mysql为mysql,pgsql为postgresql
.rectype=0
''记录总数(>0为另外取值再赋予或者固定值,0执行count设置存cookies,-1执行count不设置cookies)
.jsurl="" ''cls_jspage.js的路径
.pkey="mid" ''主键
.field="mid,ip2,country,city"
.table="dv_address"
.condition="" ''条件,不需要where
.orderby="mid desc" ''排序,不需要order by,需要asc或者desc
end with
ireccount=ors.reccount()''记录总数
irs=ors.resultset() ''返回resultset
if ireccount<1 then%>
<tr bgcolor="">
<td >暂无记录</td>
</tr>
<%
else
for i=0 to ubound(irs,2)%>
<tr bgcolor="#ffffff">
<td><%=irs(0,i)%></td>
<td><%=irs(1,i)%></td>
<td><%=left(irs(2,i),20)%></td>
<td><%=irs(3,i)%></td>
</tr><%
next
end if
%>
</table>
<table width="760" border="0" cellspacing="2" cellpadding="2" align="center">
<tr>
<td>
<%ors.showpage()%>
</td>
</tr>
</table>
<table width="760" border="0" align="center" cellpadding="2" cellspacing="2">
<tr>
<td align="center">
<%endtime=timer()%>
本页面执行时间:<%=formatnumber((endtime-startime)*1000,3)%>毫秒</td>
</tr>
</table>
</body>
</html>
<%
irs=null
ors=null
set ors=nothing
%>
demomssql.asp
<%@language="vbscript" codepage="936"%>
<!--#include file="cls_vbspage.asp"-->
<%
''-----------------------------------------------------------------------------------------------
on error resume next
dim startime,endtime
''统计执行时间
startime=timer()
''连接数据库
dim db,conn,rs
strsqlservername = "(local)" ''服务器名称或地址
strsqldbusername = "sa" ''数据库帐号
strsqldbpassword = "19811030" ''数据库密码
strsqldbname = "showotemp" ''数据库名称
set conn = server.createobject("adodb.connection")
db = "provider=sqloledb.1;persist security info=false;server=" & strsqlservername & ";user id=" & strsqldbusername & ";password=" & strsqldbpassword & ";database=" & strsqldbname & ";"
conn.open db
''-----------------------------------------------------------------------------------------------
%>
<html>
<head>
<title>叶子asp分页类-mssql调用示范</title>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
table { font-size: 12px}
a { font-size: 12px; color: #000000; text-decoration: none}
-->
</style>
</head>
<body bgcolor="#ffffff" text="#000000">
<table width="760" border="0" cellspacing="2" cellpadding="2" align="center" height="30">
<tr>
<td> </td>
</tr>
</table>
<table width="760" border="1" cellspacing="0" cellpadding="4" align="center" bordercolordark="#ffffff" bordercolorlight="#cccccc">
<tr align="center">
<td width="20">id</td>
<td>标题</td>
<td>内容(显示前20个字)</td>
<td>时间</td>
</tr>
<%
dim ors
set ors=new cls_vbspage ''创建对象
set ors.conn=conn ''得到数据库连接对象
with ors
.pagesize=13 ''每页记录条数
.pagesize=13 ''每页记录条数
.pagename="pages" ''cookies名称
.dbtype="mssql"
''数据库类型,ac为access,mssql为sqlserver2000存储过程版,mysql为mysql,pgsql为postgresql
.rectype=0
''记录总数(>0为另外取值再赋予或者固定值,0执行count设置存cookies,-1执行count不设置cookies)
.jsurl="" ''cls_jspage.js的路径
.pkey="mid" ''主键
.field="mid,ip2,country,city"
.table="tbtemppage"
.condition="" ''条件,不需要where
.orderby="mid asc" ''排序,不需要order by,需要asc或者desc
end with
ireccount=ors.reccount()''记录总数
irs=ors.resultset() ''返回resultset
if ireccount<1 then%>
<tr bgcolor="">
<td >暂无记录</td>
</tr>
<%
else
for i=0 to ubound(irs,2)%>
<tr bgcolor="#ffffff">
<td><%=irs(0,i)%></td>
<td><%=irs(1,i)%></td>
<td><%=left(irs(2,i),20)%></td>
<td><%=irs(3,i)%></td>
</tr><%
next
end if
%>
</table>
<table width="760" border="0" cellspacing="2" cellpadding="2" align="center">
<tr>
<td>
<%ors.showpage()%>
</td>
</tr>
</table>
<table width="760" border="0" align="center" cellpadding="2" cellspacing="2">
<tr>
<td align="center">
<%endtime=timer()%>
本页面执行时间:<%=formatnumber((endtime-startime)*1000,3)%>毫秒</td>
</tr>
</table>
</body>
</html>
<%
irs=null
ors=null
set ors=nothing
%>
name: showopage(vbs class)
rcsfile: readme.txt
revision: 0.12.20051114.f
author: yehe(叶子)
released: 2005-11-14 09:40:13
descript: asp分页类,支持access/mssql/mysql/sqlite
contact: qq:311673 msn:myehe@msn.com gt:mmyehe@gmail.com
website: http://www.yehe.org http://www.showo.com
------------------------------------------------
licenses:
本程序遵循gpl协议.
协议原文地址:http://www.gnu.org/licenses/licenses.cn.html#gpl
------------------------------------------------
thanks:
可洛: 感谢mssql分页核心部分
arbiter: 感谢部分分页思路
才子: 感谢推广
foxty: 感谢分页思路
------------------------------------------------
install:
1.具体调用方法可以看demo的asp文档.
2.mssql存储过程版的请先执行sp_util_page.sql文件添加存储过程.
3.sp调用方法:
exec sp_util_page 440000,4,10,''mid'',''mid,ip1,ip2,country,city'',''tbtemppage'',''1=1'',''mid asc''
记录条数(已有值:序外部赋值,0执行count),当前页数,每页记录数,主键,字段,表,条件(不需要where),排序(不需要order by,需要asc和desc字符)
如果不按主键排序,则排序赋值里面不能出现主键字符.
------------------------------------------------
release:
0.12
1.取text字段类型bug修正
2.存储过程bug修正
3.代码修正
0.11
1.存储过程加了非主键排序下的分页
2.去掉了mssql的非存储过程版分页
0.10:
1.条件简化
2.存储过程优化
0.09:
1.排序判断部分优化
0.08:
1.vbs bug修正
0.07:
1.bug修正,包括vbs类和js
0.06beta:
1.js浏览器兼容优化
2.类几个函数的bug修正
0.05beta:
1.全面代码优化,mysql/sqlite支持
2.参数输入方式修改
0.04beta:
1.做到调用代码一样适应多种数据库集成分页
2.js去掉了表单,支持静态提交
3.加上了存储过程
0.03beta:
1.公开发布的显示为0.02,其实为0.03,分为ac版类,mssql版类发布
2.js的bug修正
3.写成了类,进一步方便调用
0.02beta:
1.加上对mssql的支持
2.封装成了函数版,方便调用
3.js文件的优化
0.01beta:
1.没有写成函数,只是找到了比较快的ac分页方法
2.分页样式用js显示
------------------------------------------------
file:
db/ip.mdb access测试数据库
db/ip mssql备份测试数据库
cls_vbspage.asp 分页类
cls_jspage.js js分页样式
sp_util_page.sql mssql存储过程
demoac.asp ac分页调用示范
demomssql.asp mssql调用示范
demomssql_sp.asp mssql存储过程调用示范
cls_vbspage.asp
<%
class cls_vbspage
private oconn ''连接对象
private ipagesize ''每页记录数
private spagename ''地址栏页数参数名
private sdbtype
''数据库类型,ac为access,mssql为sql server2000存储过程版,mysql为mysql,pgsql为postgresql
private irectype ''记录总数(>0为另外取值再赋予或者固定值,0执行count设置存cookies,-1执行count不设置cookies)
private sjsurl ''cls_jspage.js的路径
private sfield ''字段名
private stable ''表名
private scondition ''条件,不需要where
private sorderby ''排序,不需要order by,需要asc或者desc
private spkey ''主键,必写
private ireccount
''================================================================
'' class_initialize 类的初始化
''================================================================
private sub class_initialize
ipagesize=10
spagename="page"
sdbtype="ac"
irectype=0
sjsurl=""
sfield=" * "
end sub
''================================================================
'' conn 得到数据库连接对象
''================================================================
public property set conn(byref value)
set oconn=value
end property
''================================================================
'' pagesize 设置每一页记录条数,默认10记录
''================================================================
public property let pagesize(byval intpagesize)
ipagesize=checknum(intpagesize,0,0,ipagesize,0)
end property
''================================================================
'' pagename 地址栏页数参数名
''================================================================
public property let pagename(byval strpagename)
spagename=iif(len(strpagename)<1,spagename,strpagename)
end property
''================================================================
'' dbtype 得到数据库类型
''================================================================
public property let dbtype(byval strdbtype)
sdbtype=ucase(iif(len(strdbtype)<1,sdbtype,strdbtype))
end property
''================================================================
'' rectype 取记录总数(>0为赋值或者固定值,0执行count设置存cookies,-1执行count不设置cookies适用于搜索)
''================================================================
public property let rectype(byval intrectype)
irectype=checknum(intrectype,0,0,irectype,0)
end property
''================================================================
'' jsurl 取得cls_jspage.js的路径
''================================================================
public property let jsurl(byval strjsurl)
sjsurl=strjsurl
end property
''================================================================
'' pkey 取得主键
''================================================================
public property let pkey(byval strpkey)
spkey=strpkey
end property
''================================================================
'' field 取得字段名
''================================================================
public property let field(byval strfield)
sfield=iif(len(strfield)<1,sfield,strfield)
end property
''================================================================
'' table 取得表名
''================================================================
public property let table(byval strtable)
stable=strtable
end property
''================================================================
'' condition 取得条件
''================================================================
public property let condition(byval strcondition)
s=strcondition
scondition=iif(len(s)>2," where "&s,"")
end property
''================================================================
'' orderby 取得排序
''================================================================
public property let orderby(byval strorderby)
s=strorderby
sorderby=iif(len(s)>4," order by "&s,"")
end property
''================================================================
'' reccount 修正记录总数
''================================================================
public property get reccount()
if irectype>0 then
i=irectype
elseif irectype=0 then
i=checknum(request.cookies("showopage")(spagename),1,0,0,0)
s=trim(request.cookies("showopage")("scond"))
if i=0 or scondition<>s then
i=oconn.execute("select count("&spkey&") from "&stable&" "&scondition,0,1)(0)
response.cookies("showopage")(spagename)=i
response.cookies("showopage")("scond")=scondition
end if
else
i=oconn.execute("select count("&spkey&") from "&stable&" "&scondition,0,1)(0)
end if
ireccount=i
reccount=i
end property
''================================================================
'' resultset 返回分页后的记录集
''================================================================
public property get resultset()
s=null
''记录总数
i=ireccount
''当前页
if i>0 then
ipagecount=abs(int(-abs(i/ipagesize)))''页数
ipagecurr=checknum(request.querystring(spagename),1,1,1,ipagecount)''当前页
select case sdbtype
case "mssql" ''sqlserver2000数据库存储过程版
set rs=server.createobject("adodb.recordset")
set cm=server.createobject("adodb.command")
cm.commandtype=4
cm.activeconnection=oconn
cm.commandtext="sp_util_page"
cm.parameters(1)=i
cm.parameters(2)=ipagecurr
cm.parameters(3)=ipagesize
cm.parameters(4)=spkey
cm.parameters(5)=sfield
cm.parameters(6)=stable
cm.parameters(7)=replace(scondition," where ","")
cm.parameters(8)=replace(sorderby," order by ","")
rs.cursorlocation=3
rs.locktype=1
rs.open cm
case "mysql" ''mysql数据库
resultset_sql="select "&sfield&" from "&stable&" "&scondition&" "&sorderby&" limit "&(ipagecurr-1)*ipagesize&","&ipagesize
set rs=oconn.execute(resultset_sql)
case else ''其他情况按最原始的方法处理(ac同理)
set rs = server.createobject ("adodb.recordset")
resultset_sql="select "&sfield&" from "&stable&" "&scondition&" "&sorderby
rs.open resultset_sql,oconn,1,1,&h0001
rs.absoluteposition=(ipagecurr-1)*ipagesize+1
end select
s=rs.getrows(ipagesize)
rs.close
set rs=nothing
end if
resultset=s
end property
''================================================================
'' class_terminate 类注销
''================================================================
private sub class_terminate()
if isobject(oconn) then oconn.close:set oconn=nothing
end sub
''================================================================
'' 输入:检查字符,是否有最小值,是否有最大值,最小值(默认数字),最大值
''================================================================
private function checknum(byval strstr,byval blnmin,byval blnmax,byval intmin,byval intmax)
dim i,s,imi,ima
s=left(trim(""&strstr),32):imi=intmin:ima=intmax
if isnumeric(s) then
i=cdbl(s)
i=iif(blnmin=1 and i<imi,imi,i)
i=iif(blnmax=1 and i>ima,ima,i)
else
i=imi
end if
checknum=i
end function
''================================================================
'' 输入:简化条件判断
''================================================================
private function iif(byval blnbool,byval strstr1,byval strstr2)
dim s
if blnbool then
s=strstr1
else
s=strstr2
end if
iif=s
end function
''================================================================
'' 上下页部分
''================================================================
public sub showpage()%>
<script language="javascript" type="text/javascript" src="<%=sjsurl%>cls_jspage.js"></script>
<script language="javascript" type="text/javascript">
var s= new cls_jspage(<%=ireccount%>,<%=ipagesize%>,3,"s");
s.setpagese("<%=spagename%>=","");
s.setpageinput("<%=spagename%>");
s.seturl("");
s.setpagefrist("首页","<<");
s.setpageprev("上页","<");
s.setpagenext("下页",">");
s.setpagelast("尾页",">>");
s.setpagetext("[{$pagenum}]","第{$pagenum}页");
s.setpagetextf(" {$pagetextf} "," {$pagetextf} ");
s.setpageselect("{$pagenum}","第{$pagenum}页");
s.setpagecss("","","");
s.sethtml("共{$reccount}记录 页次{$page}/{$pagecount} 每页{$pagesize}条 {$pagefrist} {$pageprev} {$pagetext} {$pagenext} {$pagelast} {$pageinput} {$pageselect}");
s.write();
</script>
<%end sub
end class%>
cls_jspage.js
/**
*=================================================================
*name: 叶子js分页样式(showopage style with js)
*rcsfile: cls_jspage.js
*revision: 0.09
*author: yehe(叶子)
*released: 2005-05-12 23:00:15
*description: js分页样式,显示上一页下一页的翻页结果
*contact: qq:311673,msn:myehe@msn.com
*website: http://www.yehe.org,http://www.showo.com
*=================================================================
*/
function cls_jspage(ireccount,ipagesize,ipagenum,sname){
this.irc=this.formatnum(ireccount,1,0,0,0);//总记录条数
this.ips=this.formatnum(ipagesize,1,0,1,0);//每页记录数目
this.ipn=this.formatnum(ipagenum,0,0,0,0);//显示的前后页数,0为显示所有,负数为这么多页面一个跳转
this.sn=sname;//实例对象名
this.stpage="{$page}";//页数
this.stpagecount="{$pagecount}";//总页数
this.streccount="{$reccount}";//总记录数
this.stpagesize="{$pagesize}";//每页记录数
this.stpagefrist="{$pagefrist}";//首页
this.stpageprev="{$pageprev}";//上页
this.stpagenext="{$pagenext}";//下页
this.stpagelast="{$pagelast}";//尾页
this.stpagetext="{$pagetext}";//数字跳转
this.stpagetextf="{$pagetextf}";//数字跳转框架
this.stpageinput="{$pageinput}";//输入框跳转
this.stpageselect="{$pageselect}";//下拉菜单跳转
this.stpagenum="{$pagenum}";//数字页数
this.ipc=this.getpagecount();//得到页数
}
//输入 页数开始值,结尾值
cls_jspage.prototype.setpagese=function(spagestart,spageend){
var sps=spagestart,spe=spageend;
this.sps=(sps.length>0)?sps:"page=";
this.spe=(spe.length>0)?spe:"";
}
//输入 网址
cls_jspage.prototype.seturl=function(surl){
var s=surl;
this.url=(s.length>0)?s:""+document.location;
}
//输入 输入框&下拉框name值
cls_jspage.prototype.setpageinput=function(spageinput){
var spi=spageinput;
this.spi=(spi.length>0)?spi:"page";
}
//输入 语言 首页(disable,enale)
cls_jspage.prototype.setpagefrist=function(sdis,sen){
this.pf_d=sdis;
this.pf_e=sen;
}
//输入 语言 上页
cls_jspage.prototype.setpageprev=function(sdis,sen){
this.pp_d=sdis;
this.pp_e=sen;
}
//输入 语言 下页
cls_jspage.prototype.setpagenext=function(sdis,sen){
this.pn_d=sdis;
this.pn_e=sen;
}
//输入 语言 尾页
cls_jspage.prototype.setpagelast=function(sdis,sen){
this.pl_d=sdis;
this.pl_e=sen;
}
//输入 语言 数字跳转
cls_jspage.prototype.setpagetext=function(sdis,sen){
this.pt_d=sdis;//"[{$pagenum}]"
this.pt_e=sen;//"第{$pagenum}页"
}
//输入 语言 数字跳转外围模板
cls_jspage.prototype.setpagetextf=function(sdis,sen){
this.ptf_d=sdis;//" {$pagetextf} "
this.ptf_e=sen;//" {$pagetextf} "
}
//输入 语言 下拉菜单跳转
cls_jspage.prototype.setpageselect=function(sdis,sen){
this.ps_d=sdis;//"[{$pagenum}]"
this.ps_e=sen;//"第{$pagenum}页"
}
//输入 css
cls_jspage.prototype.setpagecss=function(scsspagetext,scsspageinput,scsspageselect){
this.cpt=scsspagetext;//数字跳转css
this.cpi=scsspageinput;//输入框跳转css
this.cps=scsspageselect;//下拉菜单跳转css
}
//输入 html模板
cls_jspage.prototype.sethtml=function(shtml){
this.html=shtml;//html模板
}
//计算页数
cls_jspage.prototype.getpagecount=function(){
var irc=this.irc,ips=this.ips;
var i=(irc%ips==0)?(irc/ips):(this.formatnum((irc/ips),1,0,0,0)+1);
return (i);
}
//取得模板页数和当前页数
cls_jspage.prototype.geturl=function(itype){
var s=this.url,sps=this.sps,spe=this.spe,stp=this.stpage,ipc=this.ipc;
var it=itype,i;
if (s.indexof(sps)==-1) {
s+=((s.indexof("?")==-1)?"?":"&")+sps+stp;
i=1;
}
else {
sreg="(\\s.*)"+this.formatreg(sps)+"(\\d*)"+this.formatreg(spe)+"(\\s.*|\\s*)";
var spindex=this.reg(s,sreg,"$3");
s=s.replace(sps+spindex+spe,sps+stp+spe);
i=this.formatnum(spindex,1,1,0,ipc);
}
s=this.reg(s,"(&+)","&");
s=this.reg(s,"(\\?&)","?");
return (it==0?s:i);
}
//页面跳转
cls_jspage.prototype.pagejump=function(){
var spl,spv,sp;
var su=this.geturl(0),ipi=this.geturl(1);
var spi=this.spi,stp=this.stpage,ipc=this.ipc;
spl=document.getelementsbyname(spi).length;
for (var i=0;i<spl;i++) {
spv=document.getelementsbyname(spi)[i].value;
sp=this.formatnum(spv,1,1,0,ipc);
if (sp>0) {
location.href=su.replace(stp,sp);
break;
}
}
}
//输出
cls_jspage.prototype.write=function(){
var su=this.geturl(0),ipi=this.geturl(1);
var sn=this.sn,spi=this.spi;
var ipc=this.ipc,ipn=this.ipn;;
var irc=this.irc,ips=this.ips;
var pf_d=this.pf_d,pf_e=this.pf_e;
var pp_d=this.pp_d,pp_e=this.pp_e;
var pn_d=this.pn_d,pn_e=this.pn_e;
var pl_d=this.pl_d,pl_e=this.pl_e;
var pt_d=this.pt_d,pt_e=this.pt_e;
var ptf_d=this.ptf_d,ptf_e=this.ptf_e;
var ps_d=this.ps_d,ps_e=this.ps_e;
var cpt=this.cpt,cpi=this.cpi;
var cps=this.cps,ipn=this.ipn;
var s=this.html;
stpage=this.stpage;
stpagecount=this.stpagecount;
streccount=this.streccount;
stpagesize=this.stpagesize;
stpfrist=this.stpagefrist;
stpprev=this.stpageprev;
stpnext=this.stpagenext;
stplast=this.stpagelast;
stptext=this.stpagetext;
stptextf=this.stpagetextf;
stpinput=this.stpageinput;
stpselect=this.stpageselect;
stpagenum=this.stpagenum;
var prevp=this.formatnum((ipi-1),1,1,1,ipc),nextp=this.formatnum((ipi+1),1,1,1,ipc);
var fu,pu,nu,lu;
var s1="<span class=\""+cpt+"\"><a href=\"",s2="\">",s3="</a></span>";
var s4="<span class=\""+cpt+"\">",s5="</span>";
if (ipi<=1&&ipc<=1) {
fu=s4+pf_d+s5;
pu=s4+pp_d+s5;
nu=s4+pn_d+s5;
lu=s4+pl_d+s5;
}
else if (ipi==1&&ipc>1) {
fu=s4+pf_d+s5;
pu=s4+pp_d+s5;
nu=s1+su.replace(stpage,nextp)+s2+pn_e+s3;
lu=s1+su.replace(stpage,ipc)+s2+pl_e+s3;
}
else if (ipi==ipc) {
fu=s1+su.replace(stpage,1)+s2+pf_e+s3;
pu=s1+su.replace(stpage,prevp)+s2+pp_e+s3;
nu=s4+pn_d+s5;
lu=s4+pl_d+s5;
}
else {
fu=s1+su.replace(stpage,1)+s2+pf_e+s3;
pu=s1+su.replace(stpage,prevp)+s2+pp_e+s3;
nu=s1+su.replace(stpage,nextp)+s2+pn_e+s3;
lu=s1+su.replace(stpage,ipc)+s2+pl_e+s3;
}
var pagestart,pageend;
if (ipn<0) {
ipn=math.abs(ipn);
pagestart=(ipi%ipn==0)?(ipi/ipn):(this.formatnum((ipi/ipn),1,0,0,0));
pagestart=(pagestart*ipn==ipi)?((pagestart-1)*ipn+1):(pagestart*ipn+1);
pageend=this.formatnum(pagestart+ipn,0,1,0,ipc)
}
else if (ipn==0) {
pagestart=1;
pageend=ipc;
}
else {
pagestart=this.formatnum((ipi-ipn),1,0,1,0);
pageend=this.formatnum((pagestart+ipn*2),0,1,0,ipc);
pagestart=(pageend==ipc)?this.formatnum((pageend-ipn*2),1,0,1,0):pagestart;
}
var pselect="",ptext="",pinput="",p;
if (ipc>=1) {
pselect="<select class=\""+cps+"\" name=\""+spi+"\" onchange=\""+sn+".pagejump()\">";
pinput="<input class=\""+cpi+"\" type=\"text\" name=\""+spi+"\" size=\"5\" maxlength=\"10\" onkeydown=\"if (event.keycode==13) "+sn+".pagejump()\">";
for (var i=pagestart;i<=pageend;i++) {
if (i!=ipi) {
p=s1+su.replace(stpage,i)+s2+pt_e.replace(stpagenum,i)+s3;
ptext+=ptf_e.replace(stptextf,p);
pselect+="<option value=\""+i+"\">"+ps_e.replace(stpagenum,i)+"</option>";
}
else {
p=s4+pt_d.replace(stpagenum,i)+s5;
ptext+=ptf_d.replace(stptextf,p);
pselect+="<option selected=\"selected\">"+ps_d.replace(stpagenum,i)+"</option>";
}
}
pselect+="</select>";
}
s=s.replace(stpage,ipi);
s=s.replace(stpagecount,ipc);
s=s.replace(streccount,irc);
s=s.replace(stpagesize,ips);
s=s.replace(stpfrist,fu);
s=s.replace(stpprev,pu);
s=s.replace(stpnext,nu);
s=s.replace(stplast,lu);
s=s.replace(stptext,ptext);
s=s.replace(stpinput,pinput);
s=s.replace(stpselect,pselect);
document.write (s);
}
//输入:欲格式化字符,是否有最小值(0表示没有,1表示有),是否有最大值,最小值(默认值),最大值
cls_jspage.prototype.formatnum=function(snum,bmin,bmax,iminnum,imaxnum){
var i,in,sn=""+snum,imin=iminnum,imax=imaxnum;
if (sn.length>0) {
in=parseint(sn,10);
i=(isnan(in))?imin:in;
i=(i<imin&&bmin==1)?imin:i;
i=(i>imax&&bmax==1)?imax:i;
}
else {
i=imin;
}
return (i);
}
//输入:欲正则字符,正则表达式,替换后字符
cls_jspage.prototype.reg=function(sstr,sreg,sre){
var s="",ss=sstr,sr=sreg,sre=sre;
if ((ss.length>0)&&(sr.length>0)) {
eval("re=/"+sr+"/gim;");
s=ss.replace(re,sre);
}
return (s);
}
//格式化正则中的特殊字符
cls_jspage.prototype.formatreg=function(sreg){
var s="",sr=sreg;
var sf=new array ("/",".","+","[","]","{","}","$","^","?","*");
if (sr.length>0) {
for (var i=0;i<=sf.length;i++) {
sr=sr.replace(sf[i],"\\"+sf[i]);
}
s="("+sr+")";
}
return (s);
}
demoac.asp
<%@language="vbscript" codepage="936"%>
<!--#include file="cls_vbspage.asp"-->
<%
''-----------------------------------------------------------------------------------------------
on error resume next
dim startime,endtime
''统计执行时间
startime=timer()
''连接数据库
dim db,conn,rs
db = "provider=microsoft.jet.oledb.4.0;data source=" & server.mappath("db/ip.mdb")
set conn = server.createobject("adodb.connection")
conn.open db
''-----------------------------------------------------------------------------------------------
%>
<html>
<head>
<title>叶子asp分页类-access调用示范</title>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
table { font-size: 12px}
a { font-size: 12px; color: #000000; text-decoration: none}
-->
</style>
</head>
<body bgcolor="#ffffff" text="#000000">
<table width="760" border="0" cellspacing="2" cellpadding="2" align="center" height="30">
<tr>
<td> </td>
</tr>
</table>
<table width="760" border="1" cellspacing="0" cellpadding="4" align="center" bordercolordark="#ffffff" bordercolorlight="#cccccc">
<tr align="center">
<td width="20">id</td>
<td>标题</td>
<td>内容(显示前20个字)</td>
<td>时间</td>
</tr>
<%
dim ors
set ors=new cls_vbspage ''创建对象
set ors.conn=conn ''得到数据库连接对象
with ors
.pagesize=13 ''每页记录条数
.pagename="pages" ''cookies名称
.dbtype="ac"
''数据库类型,ac为access,mssql为sqlserver2000存储过程版,mysql为mysql,pgsql为postgresql
.rectype=0
''记录总数(>0为另外取值再赋予或者固定值,0执行count设置存cookies,-1执行count不设置cookies)
.jsurl="" ''cls_jspage.js的路径
.pkey="mid" ''主键
.field="mid,ip2,country,city"
.table="dv_address"
.condition="" ''条件,不需要where
.orderby="mid desc" ''排序,不需要order by,需要asc或者desc
end with
ireccount=ors.reccount()''记录总数
irs=ors.resultset() ''返回resultset
if ireccount<1 then%>
<tr bgcolor="">
<td >暂无记录</td>
</tr>
<%
else
for i=0 to ubound(irs,2)%>
<tr bgcolor="#ffffff">
<td><%=irs(0,i)%></td>
<td><%=irs(1,i)%></td>
<td><%=left(irs(2,i),20)%></td>
<td><%=irs(3,i)%></td>
</tr><%
next
end if
%>
</table>
<table width="760" border="0" cellspacing="2" cellpadding="2" align="center">
<tr>
<td>
<%ors.showpage()%>
</td>
</tr>
</table>
<table width="760" border="0" align="center" cellpadding="2" cellspacing="2">
<tr>
<td align="center">
<%endtime=timer()%>
本页面执行时间:<%=formatnumber((endtime-startime)*1000,3)%>毫秒</td>
</tr>
</table>
</body>
</html>
<%
irs=null
ors=null
set ors=nothing
%>
demomssql.asp
<%@language="vbscript" codepage="936"%>
<!--#include file="cls_vbspage.asp"-->
<%
''-----------------------------------------------------------------------------------------------
on error resume next
dim startime,endtime
''统计执行时间
startime=timer()
''连接数据库
dim db,conn,rs
strsqlservername = "(local)" ''服务器名称或地址
strsqldbusername = "sa" ''数据库帐号
strsqldbpassword = "19811030" ''数据库密码
strsqldbname = "showotemp" ''数据库名称
set conn = server.createobject("adodb.connection")
db = "provider=sqloledb.1;persist security info=false;server=" & strsqlservername & ";user id=" & strsqldbusername & ";password=" & strsqldbpassword & ";database=" & strsqldbname & ";"
conn.open db
''-----------------------------------------------------------------------------------------------
%>
<html>
<head>
<title>叶子asp分页类-mssql调用示范</title>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
table { font-size: 12px}
a { font-size: 12px; color: #000000; text-decoration: none}
-->
</style>
</head>
<body bgcolor="#ffffff" text="#000000">
<table width="760" border="0" cellspacing="2" cellpadding="2" align="center" height="30">
<tr>
<td> </td>
</tr>
</table>
<table width="760" border="1" cellspacing="0" cellpadding="4" align="center" bordercolordark="#ffffff" bordercolorlight="#cccccc">
<tr align="center">
<td width="20">id</td>
<td>标题</td>
<td>内容(显示前20个字)</td>
<td>时间</td>
</tr>
<%
dim ors
set ors=new cls_vbspage ''创建对象
set ors.conn=conn ''得到数据库连接对象
with ors
.pagesize=13 ''每页记录条数
.pagesize=13 ''每页记录条数
.pagename="pages" ''cookies名称
.dbtype="mssql"
''数据库类型,ac为access,mssql为sqlserver2000存储过程版,mysql为mysql,pgsql为postgresql
.rectype=0
''记录总数(>0为另外取值再赋予或者固定值,0执行count设置存cookies,-1执行count不设置cookies)
.jsurl="" ''cls_jspage.js的路径
.pkey="mid" ''主键
.field="mid,ip2,country,city"
.table="tbtemppage"
.condition="" ''条件,不需要where
.orderby="mid asc" ''排序,不需要order by,需要asc或者desc
end with
ireccount=ors.reccount()''记录总数
irs=ors.resultset() ''返回resultset
if ireccount<1 then%>
<tr bgcolor="">
<td >暂无记录</td>
</tr>
<%
else
for i=0 to ubound(irs,2)%>
<tr bgcolor="#ffffff">
<td><%=irs(0,i)%></td>
<td><%=irs(1,i)%></td>
<td><%=left(irs(2,i),20)%></td>
<td><%=irs(3,i)%></td>
</tr><%
next
end if
%>
</table>
<table width="760" border="0" cellspacing="2" cellpadding="2" align="center">
<tr>
<td>
<%ors.showpage()%>
</td>
</tr>
</table>
<table width="760" border="0" align="center" cellpadding="2" cellspacing="2">
<tr>
<td align="center">
<%endtime=timer()%>
本页面执行时间:<%=formatnumber((endtime-startime)*1000,3)%>毫秒</td>
</tr>
</table>
</body>
</html>
<%
irs=null
ors=null
set ors=nothing
%>
上一篇: jb51内容分页函数 原创
下一篇: ASP利用Google实现在线翻译功能