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 records per page * $ Total number of pagenum records * $ Page $ _ get [page] * $ Init: Minimum number of numeric pages. The default value is 1, which is generally not changed. * $ Page_len: Number of pagination pages. */ $ Model = new getpages (10, $ 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'].' '; } // Output paging information Echo $ model-> getpage (); ?> Page. class. php /* * Author: Chen Kai * Data: 2010-09-14 */ Class getpages { Public $ pagesize; // record per page Public $ offset; // number of start records Public $ pagenum; // total record Public $ page; // the current page number. Public $ init; // The leftmost number of The number page Public $ page_len; // the rightmost number of The number page Public $ pages; // the total number of pages. // Initialize the value assignment. Function _ construct ($ pagesize, $ pagenum, $ page, $ init = 1, $ page_len = 7) { $ This-> pagesize = $ pagesize; // records per page $ This-> pagenum = $ pagenum; // total record $ This-> page = $ page; $ This-> pages = ceil ($ this-> pagenum/$ this-> pagesize); // total number of pages If (empty ($ this-> page) | $ this-> page <1 | $ this-> page> $ this-> pages) $ this-> page = 1; $ This-> init = $ init; // left-side numeric Paging $ This-> page_len = $ page_len; // right of the number page $ This-> offset = ($ this-> page-1) * $ this-> pagesize; } // Output page 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 exists $ Pagenav = "Total". $ this-> pages. "Page". $ this-> pagenum. "bar "; If ($ this-> page = 1) { $ Pagenav. = "Homepage "; $ Pagenav. = "Previous Page "; } Else { $ Pagenav. = "get_url ()." = 1 'class = 'P'> Homepage "; $ Pagenav. = "get_url ()." = ". $ this-> prepg." 'class = 'P'> previous page "; } $ Pagenav. = $ this-> getvalpage (); // numeric Paging If ($ this-> page ==$ this-> pages) { $ Pagenav. = "next page "; $ Pagenav. = "last page "; } Else { $ Pagenav. = "get_url ()." = ". $ this-> nextpg." 'class = 'P'> next page "; $ Pagenav. = "get_url ()." = ". $ this-> pages." 'class = 'P'> last page "; } |