<?php mysql_connect (' localhost ', ' root ', '); mysql_select_db (' News '); mysql_query (' Set names GBK '); $sql = mysql_query ("select * from ' V_char '"); $num = mysql_num_rows ($sql); Include ' page.class.php '; /* Parameter Description: *getpages ($pagesize, $pagenum, $page, $init, $page _len); * $pagesize per page record * Total number of $pagenum records * $page $_get[page] * $init The minimum number of paging, the default is 1, generally do not have to change. * $page number of _len digital paging. */ $model = new GetPages (ten, $num, $_get[' page '); $sql = "SELECT * from ' V_char ' limit $model->offset, $model->pagesize"; $res = mysql_query ($sql); while ($row = Mysql_fetch_assoc ($res)) { echo $row [' ID ']. " - " . $row [' name ']. ' <br> '; } Output paging information echo $model->getpage (); ?> page.class.php <?php /* * Author: Chen Kai * DATA:2010-09-14 */ Class GetPages { Public $pagesize; Record per page Public $offset; Number of start records Public $pagenum; Total Records Public $page; Current page number Public $init; Digital pagination leftmost number Public $page _len; Digital pagination Rightmost number Public $pages; Total pages
Initialize the assignment. function __construct ($pagesize, $pagenum, $page, $init =1, $page _len=7) { $this->pagesize = $pagesize;//per page record $this->pagenum = $pagenum; Total Records $this->page = $page; $this->pages = ceil ($this->pagenum/$this->pagesize); Total pages if (Empty ($this->page) | | $this->page <1 | | $this->page > $this->pages) $this->page=1; $this->init = $init; Digital paging left $this->page_len = $page _len;//Digital Paging right $this->offset = ($this->page-1) * $this->pagesize; }
Output page Paging function GetPage () { $this->PREPG = $this->page-1; Previous page $this->nextpg= ($this->page = = $this->pages)? 0: $this->page+1; Next page if ($this->pages = = 1) return false; If only one page jumps out $pagenav = "<span class= ' divs ' >". $this->pages. " Page ". $this->pagenum." Article </span> "; if ($this->page = = 1) { $pagenav. = "<a href= ' # ' class= ' div ' > Home </a>"; $pagenav. = "<a href= ' # ' class= ' div ' > prev </a>"; } Else { $pagenav. = "<a href= '". $this->get_url (). " =1 ' class= ' div ' > Home </a> '; $pagenav. = "<a href= '". $this->get_url (). " = ". $this->prepg." ' class= ' div ' > prev </a> '; }
$pagenav. = $this->getvalpage (); Digital paging
if ($this->page = = $this->pages) { $pagenav. = "<a href= ' # ' class= ' div ' > next page </a>"; $pagenav. = "<a href= ' # ' class= ' div ' > Last </a>"; } Else { $pagenav. = "<a href= '". $this->get_url (). " = ". $this->nextpg." ' class= ' div ' > Next </a> '; $pagenav. = "<a href= '". $this->get_url (). " = ". $this->pages." ' class= ' div ' > Last </a> '; } |