PHP simple paging function
Function getask () {$ SQL = "select * from cms_ask where ansower <>'' "; // change the value to the method $ q_sq = mysql_query ($ SQL ); $ count = mysql_num_rows ($ q_sq); $ page_size = 8; $ page_current = isset ($ GLOBALS ['Page'])? Intval ($ GLOBALS ['Page']): 1; $ page_count = ceil ($ count/$ page_size); $ page_start = $ page_current-4; $ page_end = $ page_current + 4; if ($ page_current <5) {$ page_start = 1; $ page_end = 5;} if ($ page_current> $ page_count-4) {$ page_start = $ page_count-8; $ page_end = $ page_count;} if ($ page_start <1) $ page_start = 1; if ($ page_end> $ page_count) $ page_end = $ page_count; $ pagebar = ""; $ SQL = "select * fr Om cms_ask where ansower <> ''Order by id desc limit ". ($ page_current-1) * $ page_size ). ",". $ page_size; $ row = $ this-> user-> getall ("$ SQL"); foreach ($ row as $ v) {echo 'Q :'. $ v ["question"]. 'answer :'. $ v ["ansower"]. date ("Y-m-d H: I: s", $ v ["postTime"]). '';} $ pagebar. = ""; $ pagebar. = ""; if ($ page_current! = 1) {$ pagebar. = 'first';} for ($ I = $ page_start; $ I <= $ page_end; $ I ++) {if ($ I = $ page_current) {$ pagebar. = "". $ I. "";} else {$ pagebar. = "". $ I. "" ;}} if ($ page_current! = $ Page_count) {$ pagebar. = "END" ;}$ pagebar. = ""; $ pagebar. = ""; echo $ pagebar ;}
The above is the content of the PHP simple paging function. For more information, see The PHP Chinese website (www.php1.cn )!