This is a simple and practical php paging code. If you are a beginner of php, let's take a look at this practical paging code. This is a simple and practical php paging code. If you are a beginner of php, let's take a look at this practical paging code.
Script ec (2); script
The Code is as follows: |
|
Function page ($ SQL, $ pagesize = 10, $ class = ""){ If (! Is_string ($ SQL) {return 0; exit ;} $ Result = mysql tutorial _ query ($ SQL ); If (! $ Result) {return 0; exit ;} If (! $ Recordnum = mysql_num_rows ($ result) {return 0; exit ;} $ Totalpage = ceil ($ recordnum/$ pagesize ); $ Page = (int) $ _ get ['page']; If ($ page <= 1) $ page = 1; If ($ page >=$ totalpage) $ page = $ totalpage; $ Recordno = ($ page-1) * $ pagesize; $ SQL. = "limit $ recordno, $ pagesize "; $ Result = mysql_query ($ SQL ); $ Url = $ _ server ["php_self"]; If ($ page = 1) $ str = "homepage | previous page "; Else $ str. = "homepage | previous page "; If ($ page = $ totalpage) $ str. = "| next page | last page "; Else $ str. = "| next page | last page "; $ Str. = "current $ page $ totalpage "; Return array ($ result, $ str ); } // Call Method $ SQL = "select * from images order by imid "; $ Result = page ($ SQL, 16 ); |
/*
The simple principle is to read the corresponding records in the uploaded database tutorial, so that the page is displayed.
*/