SQLite實現分頁功能php代碼分享

來源:互聯網
上載者:User
本文主要和大家介紹了php基於SQLite實現的分頁功能,結合具體執行個體形式分析了php操作SQLite資料庫實現分頁功能的相關技巧與注意事項,需要的朋友可以參考下,希望能協助到大家。


<meta charset='utf-8'><?phpclass SqlitePage{  public function __construct()  {    $this->table_name='';    $this->tj='';    $this->page_size='';    $this->current_page='';    $this->total_page='';    include_once 'sqlite_db.php';    $this->db=new SqliteDB();//可以調用他的操作方法了  }  function entrance($table_name,$page_size,$tj='')//sql中不包含limit  page_size為每頁顯示條數  {    // 首先擷取當前頁    // sql = "select * from tab where "+條件+" order by "+排序+" limit "+要顯示多少條記錄+" offset "+跳過多少條記錄;    $this->page_size=$page_size;    $this->table_name=$table_name;    $this->tj=$tj;    $this->total_page=ceil($this->db->total($this->table_name,$this->tj)/$this->page_size);    if (!isset($_GET['page'])) {      $this->current_page=1;//如果沒有page,則設定為預設第一頁    }    else{      $this->current_page=$_GET['page'];    }    if ($this->current_page>$this->total_page) {//噹噹前頁數目大於總頁數,則設定當前頁數為總頁數      $this->current_page=$this->total_page;    }    if ($this->current_page<1) {//噹噹前頁數目大於總頁數,則設定當前頁數為總頁數      $this->current_page=1;    }    $tj=$this->tj.' limit '.$this->page_size.' offset '.($this->current_page-1)*$this->page_size;    $result=$this->db->query($this->table_name,$tj);    return $result;  }  function page_bar()  {    $old_url = $_SERVER["REQUEST_URI"];    $check = strpos($old_url, '?');    $pre_urls='test';    if ($check) {//如果urls中有?      if(substr($old_url, $check+1) == '')      { //有問號,但是後面沒有跟任何參數        $first_urls=$old_url.'page=1';//首頁        $pre_urls=$old_url.'page='.($this->current_page-1);//上一頁;        $next_urls=$old_url.'page='.($this->current_page+1);//下一頁;        $end_urls=$old_url.'page='.$this->total_page;//末頁      }      else {//有問號,並且有參數        if (isset($_GET['page'])) {//如果參數中包含page參數,則登出這個參數          unset($_GET['page']);          $old_url='http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.http_build_query($_GET);        }        $first_urls=$old_url.'&page=1';//首頁        $pre_urls=$old_url.'&page='.($this->current_page-1);//上一頁;        $next_urls=$old_url.'&page='.($this->current_page+1);//下一頁;        $end_urls=$old_url.'&page='.$this->total_page;//末頁      }    }    else{// 如果沒有問號(也就是說後面沒有任何參數,則直接跟)      $first_urls=$old_url.'?page=1';      $first_urls=$old_url.'?page=1';//首頁      $pre_urls=$old_url.'?page='.($this->current_page-1);//上一頁;      $next_urls=$old_url.'?page='.($this->current_page+1);//下一頁;      $end_urls=$old_url.'?page='.$this->total_page;//末頁    }    // echo $this->table_name.'table_name';    return '    <p class="page">      <a>【共'.$this->total_page.'頁,第'.$this->current_page.'頁】</a>      <a href="'.$first_urls.'" rel="external nofollow" >首頁</a>      <a href="'.$pre_urls.'" rel="external nofollow" >上一頁</a>      <a href="'.$next_urls.'" rel="external nofollow" >下一頁</a>      <a href="'.$end_urls.'" rel="external nofollow" >末頁</a>    </p>    ';  }  public function get_total_page()  {    return ceil($this->total_record/$this->page_size);  }}// $page=new PrePage();// $res=$page->entrance('log',10);// echo "<hr />";// foreach ($res as $key => $row) {// echo $row['urls'].'<br />';// }// echo $page->page_bar();?>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.