选择显示字体大小

odbc连mssql分页的类


<?
class pages{
var &#36;cn; //连接数据库游标
var &#36;d; //连接数据表的游标
var &#36;result; //结果
var &#36;dsn; //dsn源
var &#36;user; //用户名
var &#36;pass; //密码

var &#36;total; //记录总数
var &#36;pages; //总页数
var &#36;onepage; //每页条数
var &#36;page; //当前页
var &#36;fre; //上一页
var &#36.net; //下一页
var &#36;i; //控制每页显示

##############################
######## 连接数据库 ##########
function getconnect(&#36;dsn,&#36;user,&#36;pass){
&#36;this->cn=@odbc_connect(&#36;dsn,&#36;user,&#36;pass);
if(!&#36;this->cn){
&#36;error=&quot;连接数据库出错&quot;;
&#36;this->getmess(&#36;error);
}
}

##############################
######## 进行表的查询 #########
function getdo(&#36;sql){ //从表中查询数据
&#36;this->d=@odbc_do(&#36;this->cn,&#36;sql);
if(!&#36;this->d){
&#36;error=&quot;查询时发生了小错误......&quot;;
&#36;this->getmess(&#36;error);
}
return &#36;this->d;
}
 
 #################################
######## 求表中数据的总量 #########
function gettotal(&#36;sql){
&#36;this->sql=&#36;sql;
&#36;dt=&#36;this->getdo(&#36;this->sql); //求总数的游标
&#36;this->total=odbc_result(&#36;dt,&quot;total&quot;); //这里为何不能&#36;this->d,total 为一个字段
// &#36;this->total=@odbc_num_rows(&#36;dt);  //应唠叨老大的意见,odbc_num_rows 不能用,不知为何,返回为-1
return &#36;this->total;
}

##############################
######## 进行表的查询 #########
function getlist(&#36;sql,&#36;onepage,&#36;page){
if (&#36;page<>&quot;&quot; and &#36;page<1)  //当此页小于时的处理
&#36;page=1;
&#36;this->s=&#36;sql;
&#36;this->onepage=&#36;onepage; //每页显示的记录数
&#36;this->page=&#36;page; //页数
&#36;this->dlist=&#36;this->getdo(&#36;this->s); //连接表的游标
&#36;this->pages=ceil(&#36;this->total/&#36;this->onepage);  //计算大于指定数的最小整数
if (&#36;this->page>&#36;this->pages) //当此页大于最大页的处理
&#36;this->page=&#36;this->pages;
if(&#36;this->pages==0)
&#36;this->pages++; //不能取到第0页
if(!isset(&#36;this->page))
&#36;this->page=1;
&#36;this->fre = &#36;this->page-1; //将显示的页数
&#36;this->nxt = &#36;this->page+1;
&#36;this->nums=(&#36;this->page-1)*&#36;this->onepage;
return &#36;this->dlist;
}

##############################
function getfetch_row(&#36;dlist){
return odbc_fetch_row(&#36;dlist);
}  

 ##############################
function getresult(&#36;dlist,&#36;num){
return odbc_result(&#36;dlist,&#36;num);
}
##############################
######## 翻页 ################
function getfanye(){
&#36;str=&quot;&quot;;
if(&#36;this->page!=1)
&#36;str.=&quot;<form name=go2to form method=post action='&quot;.&#36;php_self.&quot;'><a href=&quot;.&#36;php_self.&quot;?page=1> 首页 </a><a href=&quot;.&#36;php_self.&quot;?page=&quot;.&#36;this->fre.&quot;> 前页 </a>&quot;;
else
&#36;str.=&quot;<font color=999999>首页 前页</font>&quot;;
if(&#36;this->page<&#36;this->pages)
&#36;str.=&quot;<a href=&quot;.&#36;php_self.&quot;?page=&quot;.&#36;this->nxt.&quot;> 后页 </a>&quot;;
else
&#36;str.=&quot;<font color=999999> 后页 </font>&quot;;
if(&#36;this->page!=&#36;this->pages)
&#36;str.=&quot;<a href=&quot;.&#36;php_self.&quot;?page=&quot;.&#36;this->pages.&quot;> 尾页 </a>&quot;;
else
&#36;str.=&quot;<font color=999999> 尾页 </font>&quot;;

&#36;str.=&quot;共&quot;.&#36;this->pages.&quot;页&quot;;
&#36;str.=&quot;<font color='000064'> 转到 第<input type='text' name='page' size=2 maxlength=3 style='font-size: 9pt; color:#00006a; position: relative; height: 18' value=&quot;.&#36;this->page.&quot;>页</font> &quot;;
&#36;str.=&quot;<input class=button type='button' value='确 定' onclick=check() style='font-family: 宋体; font-size: 9pt; color: #000073; position: relative; height: 19'></form>&quot;;
return &#36;str;
}

####################################
######## 对进行提交表单的验验 #########
function check()
{
 if (isnan(go2to.page.value))
echo &quot;javascript:alert('请正确填写转到页数!');&quot;;
else if (go2to.page.value==&quot;&quot;){
echo &quot;javascript:alert('请输入转到页数!');&quot;;
 }
 else{
go2to.submit();
 }
}

function getnums(){  //每页最初的记录数
return &#36;this->nums;
}

function getonepage(){ //每页实际条数
return &#36;this->onepage;
}

function geti(){ //暂未用
// &#36;this->i=&#36;this-pageone*(&#36;this->page-1)
return &#36;this->i;
}

function getpage(){
return &#36;this->page;
}

function getmess(&#36;error){ //定制消息
echo&quot;<center>&#36;error</center>&quot;;
exit;
}
}
?>

<?php
// 测试程序
&#36;pg=new pages();
&#36;pg->getconnect(&quot;dsn&quot;,&quot;user&quot;,&quot;password&quot;);
&#36;pg->gettotal(&quot;select count(*) as total from bul_file&quot;); //连学生表求总数
&#36;pg->getlist(&#36;sql,3,&#36;page);
if(&#36;pg->getnums()!=0){
 for(&#36;i=0;&#36;i<&#36;pg->getnums();&#36;pg->getfetch_row(&#36;pg->dlist),&#36;i++); //同上
}
echo &quot;<table width=\&quot;400\&quot; border=1 cellspacing=\&quot;0\&quot; cellpadding=\&quot;0\&quot; bordercolordark=\&quot;#ffffff\&quot; bordercolorlight=\&quot;#000000\&quot;>&quot;;
echo &#36;pg->getfanye();
echo &quot;</td></tr></table>&quot;;
echo &quot;<table width=\&quot;400\&quot; border=\&quot;1\&quot; cellspacing=\&quot;0\&quot; cellpadding=\&quot;0\&quot; bordercolordark=\&quot;#ffffff\&quot; bordercolorlight=\&quot;#000000\&quot;>&quot;;
echo &quot;<tr bgcolor=\&quot;#ccff99\&quot;><td width=\&quot;5%\&quot;><font face=\&quot;隶书\&quot; size=\&quot;4\&quot;><div align=\&quot;center\&quot;>id</div></font></td> <td width=\&quot;50%\&quot;><font face=\&quot;隶书\&quot; size=\&quot;4\&quot;><div align=\&quot;center\&quot;>标题</div></font></td> <td width=\&quot;30%\&quot;><font face=\&quot;隶书\&quot; size=\&quot;4\&quot;><div align='center'>日期</div></font></td>  </tr>\&quot;;
&#36;i=1;
while(&#36;pg->getfetch_row(&#36;pg->dlist)){
 &#36;pg->getnums();
 echo &quot;<tr><td width=\&quot;5%\&quot;>&quot;.(&#36;pg->nums+&#36;i).&quot;</a></td><td width=\&quot;50%\&quot;><div align='center'><a href=\&quot;list_bul.php?id=&quot;.&#36;pg->getresult(&#36;pg->dlist,1).&quot;\&quot; target=\&quot;left\&quot;>&quot;.&#36;pg->getresult(&#36;pg->dlist,2).&quot;</a></div></td><td width=\&quot;30%\&quot;><div align='center'>&quot;.substr(&#36;pg->getresult(&#36;pg->dlist,4),1,10).&quot;</div></td></tr>&quot;;
 if(&#36;i==&#36;pg->getonepage()){ //跳出循环
break;
 }
&#36;i++;
?>

  


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons