用的数据库操作类,在本栏目中可找到。js跳转函数与本网的一样。

<?php
class SqlitePage{
  public function __construct() {
    $this->page_size='';//每页条数
    $this->current_page='';//当前页
    $this->total_record=0;//总记录数
    $this->total_page='';//总页数
    require_once 'database.class.php';
    $database='data.db';
    $this->db=new SQLite(dirname(__FILE__).'/'.$database);
  }
  function entrance($sql,$page_size){//sql中不包含limit  page_size为每页显示条数
    $this->page_size=$page_size;
    $this->total_record=$this->db->RecordCount($sql);
    $this->total_page=ceil($this->total_record/$this->page_size);
    if (!isset($_GET['page'])) {
      $this->current_page=1;//如果没有page,则设置为默认第一页
    }else{
      $this->current_page=$_GET['page'];
    }//if
    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($sql.$tj);
    return $result;
  }//
  
   function bar($tpl='') {
    $totalRecord=$this->total_record;
    $count = $this->get_total_page();
    $page =$this->current_page;
     if(!$tpl){
        $tpl = '[第'.$page.'页/共'.$count.'页,每页'.$this->page_size.'条,共有'.$totalRecord.'条记录]<a href=?reset>首页</a> <a href=?prve>上一页</a> <a href=?next>下一页</a> <a href=?end>尾页</a> <input type="text" id="pageGo" name="pageGo" /><input type="submit" name="pageSubmit" value="GO" onClick="newPage();" />';
    }
    $d = array(
      'reset' => 1,
      'prve' => $page > 1 ? $page - 1 : 1,
      'next' => $page < $count ? $page + 1 : $count,
      'end' => $count,
    );
    foreach($d as $k=>$v) {
      $_GET['page'] = $v;
      $tpl = str_replace($k, http_build_query($_GET), $tpl);
    }
    echo $tpl;
  }//bar
  public function get_total_page(){
    return ceil($this->total_record/$this->page_size);
  }
}//SqlitePage
/*
$page=new SqlitePage();
$res=$page->entrance('select * from article',3);
foreach ($res as $key => $row) {
echo $row['title'].'<br />';
}
echo $page->bar();
*/
?>