中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

php+mysql分頁(yè)類(lèi)

2018-07-20    來(lái)源:open-open

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬(wàn)Linux鏡像隨意使用
封裝的類(lèi):
    <?php  
    /*********************************************  
    類(lèi)名: PageSupport 
    功能:分頁(yè)顯示MySQL數(shù)據(jù)庫(kù)中的數(shù)據(jù)  
    ***********************************************/   
    class PageSupport{   
        //屬性  
        var $sql;                    //所要顯示數(shù)據(jù)的SQL查詢語(yǔ)句   
        var $page_size;                //每頁(yè)顯示最多行數(shù)   
          
        var $start_index;            //所要顯示記錄的首行序號(hào)  
        var $total_records;            //記錄總數(shù)   
        var $current_records;        //本頁(yè)讀取的記錄數(shù)   
        var $result;                //讀出的結(jié)果   
          
        var $total_pages;            //總頁(yè)數(shù)    
        var $current_page;            //當(dāng)前頁(yè)數(shù)  
        var $display_count = 30;     //顯示的前幾頁(yè)和后幾頁(yè)數(shù)  
      
        var $arr_page_query;        //數(shù)組,包含分頁(yè)顯示需要傳遞的參數(shù)   
      
        var $first;  
        var $prev;  
        var $next;  
        var $last;  
          
        //方法  
    /*********************************************  
    構(gòu)造函數(shù):__construct() 
    輸入?yún)?shù):             
            $ppage_size:每頁(yè)顯示最多行數(shù)     
    ***********************************************/   
     function PageSupport($ppage_size)  
     {   
        $this->page_size=$ppage_size;   
        $this->start_index=0;  
     }   
      
      
    /*********************************************  
    構(gòu)造函數(shù):__destruct() 
    輸入?yún)?shù):             
    ***********************************************/   
     function __destruct()  
     {  
          
     }  
              
    /*********************************************  
    get函數(shù):__get() 
    ***********************************************/   
     function __get($property_name)  
     {    
         if(isset($this->$property_name))   
         {   
                return($this->$property_name);   
         }   
         else   
         {   
                return(NULL);   
         }   
     }  
       
    /*********************************************  
    set函數(shù):__set() 
    ***********************************************/   
     function __set($property_name, $value)   
     {       
        $this->$property_name = $value;   
     }   
      
    /*********************************************  
    函數(shù)名:read_data 
    功能:    根據(jù)SQL查詢語(yǔ)句從表中讀取相應(yīng)的記錄 
    返回值:屬性二維數(shù)組result[記錄號(hào)][字段名] 
    ***********************************************/   
     function read_data()  
     {   
        $psql=$this->sql;   
          
        //查詢數(shù)據(jù),數(shù)據(jù)庫(kù)鏈接等信息應(yīng)在類(lèi)調(diào)用的外部實(shí)現(xiàn)  
        $result=mysql_query($psql) or die(mysql_error());   
        $this->total_records=mysql_num_rows($result);   
          
        //利用LIMIT關(guān)鍵字獲取本頁(yè)所要顯示的記錄  
        if($this->total_records>0)   
        {  
            $this->start_index = ($this->current_page-1)*$this->page_size;  
            $psql=$psql.    " LIMIT ".$this->start_index." , ".$this->page_size;   
              
            $result=mysql_query($psql) or die(mysql_error());   
            $this->current_records=mysql_num_rows($result);   
              
            //將查詢結(jié)果放在result數(shù)組中  
            $i=0;   
            while($row=mysql_fetch_Array($result))  
            {   
                $this->result[$i]=$row;   
                $i++;   
            }   
        }  
      
          
        //獲取總頁(yè)數(shù)、當(dāng)前頁(yè)信息  
        $this->total_pages=ceil($this->total_records/$this->page_size);    
      
        $this->first=1;  
        $this->prev=$this->current_page-1;  
        $this->next=$this->current_page+1;  
        $this->last=$this->total_pages;  
     }  
      
     /*********************************************  
    函數(shù)名:standard_navigate() 
    功能:    顯示首頁(yè)、下頁(yè)、上頁(yè)、未頁(yè) 
    ***********************************************/   
     function standard_navigate()   
     {      
        echo "<div align=center>";  
        echo "<form action=".$_SERVER['PHP_SELF']." method=\"get\">";  
          
        echo "<font color = red size ='4'>第".$this->current_page."頁(yè)/共".$this->total_pages."頁(yè)</font>";   
        echo "    ";  
          
        echo "跳到<input type=\"text\" size=\?\" name=\"current_page\" value='".$this->current_page."'/>頁(yè)";  
        echo "<input type=\"submit\" value=\"提交\"/>";  
          
      
        //生成導(dǎo)航鏈接  
        if ($this->current_page > 1) {  
          echo "<A href=".$_SERVER['PHP_SELF']."?current_page=".$this->first.">首頁(yè)</A>|";   
          echo "<A href=".$_SERVER['PHP_SELF']."?current_page=".$this->prev.">上一頁(yè)</A>|";   
        }  
      
        if( $this->current_page < $this->total_pages) {  
          echo "<A href=".$_SERVER['PHP_SELF']."?current_page=".$this->next.">下一頁(yè)</A>|";  
          echo "<A href=".$_SERVER['PHP_SELF']."?current_page=".$this->last.">末頁(yè)</A>";   
        }  
          
        echo "</form>";      
        echo "</div>";  
      
     }   
       
      /*********************************************  
    函數(shù)名:full_navigate() 
    功能:    顯示首頁(yè)、下頁(yè)、上頁(yè)、未頁(yè)   
    生成導(dǎo)航鏈接 如1 2 3 ... 10 11 
    ***********************************************/   
     function full_navigate()   
     {      
        echo "<div align=center>";  
        echo "<form action=".$_SERVER['PHP_SELF']." method=\"get\">";  
          
        echo "<font color = red size ='4'>第".$this->current_page."頁(yè)/共".$this->total_pages."頁(yè)</font>";   
        echo "    ";  
          
        echo "跳到<input type=\"text\" size=\?\" name=\"current_page\" value='".$this->current_page."'/>頁(yè)";  
        echo "<input type=\"submit\" value=\"提交\"/>";  
          
        //生成導(dǎo)航鏈接 如1 2 3 ... 10 11  
        $front_start = 1;  
        if($this->current_page > $this->display_count){  
            $front_start = $this->current_page - $this->display_count;  
        }  
        for($i=$front_start;$i<$this->current_page;$i++){  
            echo "<a href=".$_SERVER['PHP_SELF']."?page=".$i.">[".$i ."]</a> ";      
        }  
      
        echo "[".$this->current_page."]";  
      
        $displayCount = $this->display_count;  
        if($this->total_pages > $displayCount&&($this->current_page+$displayCount)<$this->total_pages){  
            $displayCount = $this->current_page+$displayCount;  
        }else{  
            $displayCount = $this->total_pages;  
        }  
      
        for($i=$this->current_page+1;$i<=$displayCount;$i++){  
            echo "<a href=".$_SERVER['PHP_SELF']."?current_page=".$i.">[".$i ."]</a> ";      
        }  
      
        //生成導(dǎo)航鏈接  
        if ($this->current_page > 1) {  
          echo "<A href=".$_SERVER['PHP_SELF']."?current_page=".$this->first.">首頁(yè)</A>|";   
          echo "<A href=".$_SERVER['PHP_SELF']."?current_page=".$this->prev.">上一頁(yè)</A>|";   
        }  
      
        if( $this->current_page < $this->total_pages) {  
          echo "<A href=".$_SERVER['PHP_SELF']."?current_page=".$this->next.">下一頁(yè)</A>|";  
          echo "<A href=".$_SERVER['PHP_SELF']."?current_page=".$this->last.">末頁(yè)</A>";   
        }  
          
        echo "</form>";      
        echo "</div>";  
      
     }   
      
    }   
    ?>  

寫(xiě)在php頁(yè)面里面的代碼:
    <div class="index">  
    <?php   
          
        include_once("fenye_php.php");   //引入類(lèi)  
          
        ///////////////////////////////////////////////////////////////////////  
        $con = mysql_connect("localhost","root","");   
        if (!$con)  
          {  
          die('Could not connect: ' . mysql_error());      
          }  
            
        mysql_select_db("myblog", $con);    //選取數(shù)據(jù)庫(kù)  
          
        $PAGE_SIZE=10;            //設(shè)置每頁(yè)顯示的數(shù)目  
          
        ///////////////////////////////////////////////////////////////////////  
      
        $pageSupport = new PageSupport($PAGE_SIZE); //實(shí)例化PageSupport對(duì)象  
          
        $current_page=$_GET["current_page"];//分頁(yè)當(dāng)前頁(yè)數(shù)  
          
        if (isset($current_page)) {  
              
            $pageSupport->__set("current_page",$current_page);  
              
        } else {  
              
            $pageSupport->__set("current_page",1);  
              
        }  
      
          
        $pageSupport->__set("sql","select * from article ");       
        $pageSupport->read_data();//讀數(shù)據(jù)  
          
        if ($pageSupport->current_records > 0) //如果數(shù)據(jù)不為空,則組裝數(shù)據(jù)  
        {  
            for ($i=0; $i<$pageSupport->current_records; $i++)  
            {  
                $title = $pageSupport->result[$i]["title"];  
                $content = $pageSupport->result[$i]["content"];  
                  
                $part=substr($content,0,400);  
                //循環(huán)輸出每條數(shù)據(jù)  
                echo '<div class="index_side">          
                    <div class="index_title">'.$title.'</div>  
                    <div class="index_content">'.$part.'</div>  
                    <div class="index_button">  
                       <a href="#">update</a>   <a href="#">delet</a>  
                    </div>  
                </div>';  
            }  
        }  
        $pageSupport->standard_navigate(); //調(diào)用類(lèi)里面的這個(gè)函數(shù),顯示出分頁(yè)HTML  
        //關(guān)閉數(shù)據(jù)庫(kù)  
        mysql_close($con);  
     ?>  
    </div>  

來(lái)自:http://blog.csdn.net/phpfenghuo/article/details/23207099

標(biāo)簽: isp Mysql 代碼 數(shù)據(jù)庫(kù)

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:C# 實(shí)現(xiàn)ping功能

下一篇:PHP 圖片的二進(jìn)制存取 (Mysql)