国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

php分頁代碼

2024-05-04 23:06:53
字體:
供稿:網(wǎng)友

這是一款簡單實用的php分頁代碼,同時也很好的利用的類的構(gòu)造函數(shù)來實例分頁的初始化,好了下面我們來看看這款代碼如何吧,代碼如下:

  1. class page extends mysql 
  2.  public $page
  3.  public $page_size
  4.  private $table
  5.  private $condition
  6.  private $limit
  7.  private $href
  8.  private $action_value
  9.  private $url_value
  10. //分頁初始化 
  11.  function __construct($page,$page_size,$table,$condition,$limit,$href,$action_value,$url_value
  12.  { 
  13.   $this->page=$page
  14.   $this->page_size=$page_size
  15.   $this->table=$table
  16.   $this->condition=$condition
  17.   $this->limit=$limit
  18.   $this->href=$href
  19.   $this->action_value=$action_value
  20.   $this->url_value=$url_value
  21.   $this->get_page(); 
  22.  } 
  23. /** 
  24.  * get the page's value判斷當(dāng)前在第幾頁 
  25.  */ 
  26.  function get_page() 
  27.  { 
  28.   if($this->page==""
  29.   { 
  30.    $this->page=1; 
  31.   } 
  32.   return $this->page; 
  33.  } 
  34. /** 
  35.  * page main code //調(diào)用轉(zhuǎn)到指定的分頁代碼號。 
  36.  */ 
  37.  function go_page() 
  38.  { 
  39.  if($this->page!=""
  40.  { 
  41.   $reslut=mysql::fn_select($this->table,'count(*) as `total`',$this->condition,'',$this->limit); 
  42.   $rs=mysql::fetch_array($reslut); 
  43.   $message_count=$rs['total'];  //get the messages's count number 
  44.   $page_count=ceil($message_count/$this->page_size);  //get the page's count number 
  45.   $offset=($this->page-1)*$this->page_size;  //get the first value of sql's limit 
  46.   if($message_count<=$this->page_size) 
  47.   { 
  48.    $page_code=array("","","",""); 
  49.   } 
  50.   else if($this->page==1) 
  51.   { 
  52.    $page_code=array(""
  53.        ""
  54.        "<a name=code href=".$this->href."?page=".($this->page+1)."&action=".$this->action_value."&".$this->url_value.">下一頁</a>"
  55.        "<a name=code href=".$this->href."?page=".$page_count."&action=".$this->action_value."&".$this->url_value.">尾頁</a>"); 
  56.   } 
  57.   else if($this->page==$page_count
  58.   { 
  59.       $page_code=array("<a name='code' href=".$this->href."?page=1&action=".$this->action_value."&".$this->url_value.">首頁</a>"
  60.        "<a name='code' href=".$this->href."?page=".($this->page-1)."&action=".$this->action_value."&".$this->url_value.">上一頁</a>"
  61.        ""
  62.        ""); 
  63.   } 
  64.   else 
  65.   { 
  66.    $page_code=array("<a name='code' href=".$this->href."?page=1&action=".$this->action_value."&".$this->url_value.">首頁</a>"
  67.        "<a name='code' href=".$this->href."?page=".($this->page-1)."&action=".$this->action_value."&".$this->url_value.">上一頁</a>"
  68.        "<a name='code' href=".$this->href."?page=".($this->page+1)."&action=".$this->action_value."&".$this->url_value.">下一頁</a>"
  69.        "<a name='code' href=".$this->href."?page=".$page_count."&action=".$this->action_value."&".$this->url_value.">尾頁</a>"); 
  70.   } 
  71.   $page_info=array
  72.       "message_count"=>$message_count
  73.       "page_count"=>$page_count
  74.       "offset"=>$offset
  75.       "page_size"=>$this->page_size, 
  76.       "page_now"=>$this->page, 
  77.       "page_first"=>$page_code[0], 
  78.       "page_up"=>$page_code[1], 
  79.       "page_next"=>$page_code[2], 
  80.       "page_one_last"=>$page_code[3] 
  81.       );//開源代碼Vevb.com 
  82.   return $page_info
  83.  } 
  84.  } 

php分頁代碼調(diào)用方法,代碼如下:

  1. $page = new page('',10,'`cy0871_users_info`','index.php',1,'','','userid=1'); 
  2. print_r ($page->go_page()); 
  3. $page_info = $page->go_page(); 
  4. echo $page_info['page']."<br/>"
  5. echo $page_info['page_size']; 

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 襄垣县| 乐都县| 垣曲县| 吴旗县| 武清区| 曲阜市| 吉林省| 海口市| 邻水| 杂多县| 东台市| 临朐县| 三都| 锦屏县| 新田县| 鄂伦春自治旗| 温宿县| 大英县| 杨浦区| 景泰县| 安远县| 丘北县| 张家川| 周宁县| 建始县| 年辖:市辖区| 赤峰市| 哈尔滨市| 墨竹工卡县| 牟定县| 山东省| 新泰市| 温泉县| 福州市| 丹凤县| 保亭| 仁化县| 富宁县| 南溪县| 玉屏| 双柏县|