PHP SQLite paging.

Source: Internet
Author: User
Tags php class

The operation database file uses the previous action class. You can refer to the previous article. I am very poor literary, nonsense not to say, directly on the code:

<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 ()//can invoke his operation method}function entrance ($table _name, $page _size, $tj = ")//sql does not contain limit Page_ Size shows the number of bars per page {//Gets the current page first//sql = "SELECT * from tab where" + Condition + "ORDER BY" + sort + "limit" + how many records to display + "offset" + how many records to skip; $this-& Gt;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;//If there is no page, set the default first page}else{$this->current_page=$_get[' page ';} if ($this->current_page> $this->total_page) {//when the current page count is greater than the total number of pages, set the current pages to the total pages $this->current_page= $this Total_page;} if ($this->current_page<1) {//when the current number of pages is greater than the total pages, set the current page to the total page $this->current_page=1;} $TJ = $this->tj. ' Limit '. $this->p age_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) {// If there are any in URLs? if (substr ($old _url, $check + 1) = = ") {//has a question mark, but is not followed by any parameter $first_urls= $old _url. ' page=1 ';//home $pre_urls= $old _url. ' Page= '. ($this->current_page-1);//prev; $next _urls= $old _url. ' page= '. ($this->current_page+1);//next page; $end _urls= $old _url. ' page= '. $this->total_page;//Last} else {//has a question mark and has a parameter if (isset ($_get[' page ')) {//If the parameter contains a page parameter, unregister this parameter unset ($_get[' page '); $old _url= ' http://'. $_server[' http_host '].$_server[' php_self ']. '? '. Http_build_query ($_get);} $first _urls= $old _url. ' &page=1 ';//home $pre_urls= $old _url. ' &page= '. ($this->current_page-1);//previous page; $next _urls= $old _url. ' &page= '. ($this->current_page+1);//next page; $end _urls= $old _url. ' &page= '. $this->total_page;//Last}}else{//if there is no question mark (that is, if there are no arguments later) $first _urls= $old _url.Page=1 '; $first _urls= $old _url. '? Page=1 ';//home $pre_urls= $old _url. '? Page= '. ($this->current_page-1);//previous page; $next _urls= $old _url. '? Page= '. ($this->current_page+1);//next page; $end _urls= $old _url. '? Page= '. $this->total_page;//last}//echo $this->table_name. ' table_name '; return ' <div class= ' page ' ><a > "Total". $this->total_page page, section '. $this->current_page. ' Page "</a><a href=" '. $first _urls. ' > Home </a><a href= "'. $pre _urls. '" > previous page </a><a href= "'. $next _urls. '" > next page </a><a href= "'. $end _urls. '" > End </a></div> ';} Public Function Get_total_page () {return ceil ($this->total_record/$this->page_size);}} $page =new prepage ()//$res = $page->entrance (' log '),//echo "

PHP SQLite paging.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.