怎么在php中利用SQLite實(shí)現(xiàn)一個(gè)分頁功能?很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。

代碼:
<meta charset='utf-8'>
<?php
class 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();//可以調(diào)用他的操作方法了
}
function entrance($table_name,$page_size,$tj='')//sql中不包含limit page_size為每頁顯示條數(shù)
{
// 首先獲取當(dāng)前頁
// 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,則設(shè)置為默認(rèn)第一頁
}
else{
$this->current_page=$_GET['page'];
}
if ($this->current_page>$this->total_page) {//當(dāng)當(dāng)前頁數(shù)目大于總頁數(shù),則設(shè)置當(dāng)前頁數(shù)為總頁數(shù)
$this->current_page=$this->total_page;
}
if ($this->current_page<1) {//當(dāng)當(dāng)前頁數(shù)目大于總頁數(shù),則設(shè)置當(dāng)前頁數(shù)為總頁數(shù)
$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) == '')
{ //有問號(hào),但是后面沒有跟任何參數(shù)
$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 {//有問號(hào),并且有參數(shù)
if (isset($_GET['page'])) {//如果參數(shù)中包含page參數(shù),則注銷這個(gè)參數(shù)
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{// 如果沒有問號(hào)(也就是說后面沒有任何參數(shù),則直接跟)
$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 '
<div 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>
</div>
';
}
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();
?>看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對(duì)創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司,的支持。
分享文章:怎么在php中利用SQLite實(shí)現(xiàn)一個(gè)分頁功能-創(chuàng)新互聯(lián)
URL標(biāo)題:http://www.yijiale78.com/article6/pgeig.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站、網(wǎng)頁設(shè)計(jì)公司、動(dòng)態(tài)網(wǎng)站、營(yíng)銷型網(wǎng)站建設(shè)、建站公司、網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容