Home  >  Article  >  Backend Development  >  A class that connects odbc to mssql paging_PHP tutorial

A class that connects odbc to mssql paging_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 16:08:58790browse


class Pages{
var $cn; //Connect the database cursor
var $d; //Connect the data table Cursor
var $result; //Result
var $dsn; > var $total; //Total number of records
var $pages; //Total number of pages
var $onepage; //Number of entries per page
var $page; //Previous page
var $net; //Next page
var $i; 🎜> $this->cn=@odbc_connect($dsn,$user,$pass);
if(!$this->cn){
$error="Error connecting to database";
                                                                                                  @odbc_do($this->cn,$sql);
If(!$this->d){
$error="A small error occurred during query...";
          $this->getMess($error); $this ->sql=$sql;
                $dT=$this->getDo($this->sql);                                                            'total');//Why can't $this->d be used here?
return $this->total;
}

function getList($sql,$onepage,$page){
$this->s=$sql;
$this->onepage=$onepage;
$this->page=$page;
$this->dList=$this->getDo($this->s); // Cursor for joining table
$this->pages=ceil($this->total/$this->onepage);
if($this->pages==0) ​​
$ this->pages++; //Cannot get page 0
if(!isset($this->page))
$this->page=1;
$this-> fre = $this->page-1; //The number of pages to be displayed
->page-1)*$this->onepage;
//if($this->nums!=0){
this->i<$pg->getNums();odbc_fetch_row($this->dd),$this->i++);//Same as above
                                                               >i=0;//Why can’t this part be encapsulated?
        return $this->dList;
    }

    function getFanye(){
        $str="";
        if($this->page!=1)
            $str.=" 首页 前页 ";
            else
                $str.="首页 前页";
        if($this->page<$this->pages)
            $str.=" 后页 ";
            else
                $str.=" 后页 ";
        if($this->page!=$this->pages)
            $str.=" 尾页 ";
            else
                $str.=" 尾页 ";

        $str.="共".$this->pages."页";
        $str.="您正浏览第".$this->page."页";
        return $str;
    }

    function getNums(){
        return $this->nums;
    }

    function getOnepage(){//每页实际条数
        return $this->onepage;
    }

    function getI(){
        return $this->i;
    }

    function getPage(){
        return $this->page;
    }

    function getMess($error){//定制消息
        echo"

$error
";
        exit;
    }
}

$pg=new Pages();
$pg->getConnect("lei","sa","star");
$pg->getTotal("select count(*) as total from xs");            //连学生表求总数
$pg->getList("select xs_name from xs order by xs_id",8,$page);
if($pg->getNums()!=0){
    for($i=0;$i<$pg->getNums();odbc_fetch_row($pg->dList),$i++);//同上
}
$i=0;
while(odbc_fetch_row($pg->dList)){
    $name=odbc_result($pg->dList,"xs_name");
    echo $name."
";
    if($i==$pg->getOnepage()){//跳出循环
        break;
    }
    $i++;
}
echo$pg->getFanye();
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/314636.htmlTechArticle!--二泉.net -- ? class Pages{ var $cn;//连接数据库游标 var $d;//连接数据表的游标 var $result;//结果 var $dsn;//dsn源 var $user;//用户名 var $pass;//密码 var...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn