This article mainly introduces the PHP based on the implementation of the paging function, combined with specific examples of the PHP operation SQLite database to achieve paging function of the relevant skills and considerations, the need for friends can refer to the following
This paper describes the paging function of PHP based on SQLite. Share to everyone for your reference, as follows:
Here the operation of the database file is used in the previous article, "The operation of the SQLite-based PDO operation class" contains additions and deletions and transactions such as operations "" SQLite database Operation class. Nonsense not to say, directly on the code:
<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 ()//can invoke his method of operation} function entrance ($table _name, $page _size, $tj = ")//sql does not contain limit Page_ Size shows the number of bars per page {//Get the current page first//sql = "SELECT * from tab where" + Condition + "ORDER BY" + sort + "limit" + how many records to display + "offset" + how many bars to skip Record $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;//if no page is set to 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 total pages $this->current_page= $this Total_page; } if ($this->curRENT_PAGE<1) {//when the current page count is greater than the total number of pages, set the current pages to total pages $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) {//If there are in URLs? if (substr ($old _url, $check + 1) = = ") {//has a question mark, but is not followed by any parameters $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 {//has a question mark and has a parameter if (isset ($_get[' page ')]) {//if the parameter Number contains the 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 ' <p class= "page" > <a> "Total". $this->total_page. ' Page, section '. $this->current_page. ' Page ' </a> <a href= "'. $first _urls. '" rel= "external nofollow" > Home </a> <a href= "'. $pre _urls. ' Rel= ' external nofoll ow > Prev </a> <a href= '. $next _urls. ' "rel=" external nofollow "> next </a> <a href=" '. $end _u RLS. ' "rel=" external nofollow "> Last </a> </p> '; } public Function Get_total_page () {return ceil ($this->total_record/$this->page_size); }}//$page =new prepage ()//$res = $page->entrance (' log '),//echo "