选择显示字体大小

写了一个odbc连mssql分页的类,请大家指教一二(原创).


   <!--二泉.net -->
<?
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,&#39;total&#39;);//这里为何不能&#36;this->d呢?
        return &#36;this->total;
    }

    function getlist(&#36;sql,&#36;onepage,&#36;page){
        &#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->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;
        //if(&#36;this->nums!=0){
        //    for(&#36;this->i=0;&#36;this->i<&#36;pg->getnums();odbc_fetch_row(&#36;this->dd),&#36;this->i++);//同上
        //}
        //&#36;this->i=0;//为何这部分不能封装?
        return &#36;this->dlist;
    }

    function getfanye(){
        &#36;str=&quot;&quot;;
        if(&#36;this->page!=1)
            &#36;str.=&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=red>&quot;.&#36;this->page.&quot;</font>页&quot;;
        return &#36;str;
    }
    
    function getnums(){
        return &#36;this->nums;
    }
    
    function getonepage(){//每页实际条数
        return &#36;this->onepage;
    }

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

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

&#36;pg=new pages();
&#36;pg->getconnect(&quot;lei&quot;,&quot;sa&quot;,&quot;star&quot;);
&#36;pg->gettotal(&quot;select count(*) as total from xs&quot;);            //连学生表求总数
&#36;pg->getlist(&quot;select xs_name from xs order by xs_id&quot;,8,&#36;page);
if(&#36;pg->getnums()!=0){
    for(&#36;i=0;&#36;i<&#36;pg->getnums();odbc_fetch_row(&#36;pg->dlist),&#36;i++);//同上
}
&#36;i=0;
while(odbc_fetch_row(&#36;pg->dlist)){
    &#36;name=odbc_result(&#36;pg->dlist,&quot;xs_name&quot;);
    echo &#36;name.&quot;<br>&quot;;
    if(&#36;i==&#36;pg->getonepage()){//跳出循环
        break;
    }
    &#36;i++;
}
echo&#36;pg->getfanye();
?>


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

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