This article provides you with one or two paging codes. There is a paging program with ultra-concise code. If you are a beginner of php, this paging code is very good. This article provides you with one or two paging codes. There is a paging program with ultra-concise code. If you are a beginner of php, this paging code is very good.
Script ec (2); script
| The Code is as follows: |
|
$ Page_total = $ num/$ pagesize_wish;
$ Page_total_int = (int) $ page_total;
If ($ page_total! = $ Page_total_int) $ page_total = $ page_total_int + 1;
For ($ I = 1; $ I <= $ page_total; $ I ++ ){
If ($ I ==$ _ get ['W']) {
Print"". $ I ."";
} Else {
If (! $ _ Get ['W']) {
If ($ I = 1 ){
Print"". $ I ."";
} Else {
Print "$ I ";
}
} Else {
Print "$ I ";
}
}
}
|
// Code 2 by PAGE
| The Code is as follows: |
|
$ Pernumber = 10; // number of records displayed on each page
$ Page = $ _ get ['page']; // obtain the current page value.
$ Count = mysql tutorial _ query ("select count (*) from user"); // obtain the total number of records
$ Rs = mysql_fetch_array ($ count );
$ Totalnumber = $ rs [0];
$ Totalpage = ceil ($ totalnumber/$ pernumber); // calculate the total number of pages
If (! Isset ($ page )){
$ Page = 1;
} // If no value exists, 1 is assigned.
$ Startcount = ($ page-1) * $ pernumber; // start by page. Calculate the start record based on this method.
$ Result = mysql_query ("select * from user limit $ startcount, $ pernumber"); // calculate the start record and number of records based on the previous calculation.
While ($ row = mysql_fetch_array ($ result )){
Echo "user_id:". $ row [0]."
";
Echo "username:". $ row [1]."
"; // Display the database tutorial content
}
If ($ page! = 1) {// the page number is not equal to 1
?>
"> Previous Page }
For ($ I = 1; $ I <= $ totalpage; $ I ++) {// The page is displayed cyclically.
?>
"> }
If ($ page <$ totalpage) {// if the page is smaller than the total number of pages, the next page Link is displayed.
?>
"> Next page }
|
?>