Without JS, php fully implements code for process-oriented data paging.

Source: Internet
Author: User

Copy codeThe Code is as follows:
<? Php
// The session set on the login page. When the session contains the name
// Session_start ();
// $ Name = $ _ SESSION ['name'];
// If (empty ($ name )){
// Header ("Location: error. php ");
// Exit ();
//}
// Process-oriented, data Paging
If (false! = ($ Mysql = mysql_connect ('local mysql', 'mysql username', 'mysql password '))){
Mysql_query ('set names utf8', $ mysql); // sets the encoding in the database.
Mysql_select_db ("database", $ mysql );
} Else {
Die ("connection failed ");
}


$ PageSize = 10; // number of entries displayed on the page
$ RowCount = 0; // The total number of data records, obtained from the database

$ SqlCount = 'select count (id) from employee ';
$ Res1 = mysql_query ($ sqlCount, $ mysql );

// Retrieve the number of data entries
If (false! = ($ Row = mysql_fetch_row ($ res1 ))){
$ RowCount = $ row [0];
}

// The total number of pages, calculated
$ PageCount = 0;
$ PageCount = ceil ($ rowCount/$ pageSize );

// Obtain the current page
If (! Isset ($ _ GET ['pagenow']) {// if get/post is empty, the default value is 1.
$ PageNow = 1; // current page number
} Elseif (false! = Is_numeric ($ _ GET ['pagenow']) & $ _ GET ['pagenow'] <= $ pageCount ){
$ PageNow = $ _ GET ['pagenow'];
} Else {
Header ("Location: ../Error/error. php ");
Exit ();
}
// Print the paging data
Echo "<div style = 'margin-left: 300px; margin-top: 1px; '> ";
Echo "<table style = 'border: 1px; border-style: solid; border-width: 1px; border-color: green'> ";
Echo "<tr> <th> id </th> <th> name </th> <th> age </th> <th> sex </th> <th> birthday </th> <th> edit employee </th> <th> Delete employee </th> </tr> ";
$ SqList = "select id, name, age, sex, birthday from employee limit". ($ pageNow-1) * $ pageSize. ",". $ pageSize;
$ Res2 = mysql_query ($ sqList, $ mysql );
While (false! = ($ Row = mysql_fetch_assoc ($ res2 ))){
Echo "<tr> <td >{$ row ['id']} </td> <td >{$ row ['name']} </td> <td> {$ row ['age'] }</td> <td >{$ row ['sex'] }</td> <td >{$ row ['birthday']} </td> <a href = #> edit </a> </td> <a href = #> Delete </a> </td> </tr> ";
}
Echo "</table> ";
// Control the number of pages displayed in the form
Echo "<form action = 'current page'> ";
// Previous page button
If ($ pageNow> 1 ){
$ PageUp = $ pageNow-1;
Echo "<a href = '? PageNow = ". $ pageUp." '> previous page </a> ";
}

// Next page button
If ($ pageNow <$ pageCount ){
$ PageDown = $ pageNow + 1;
Echo "<a href = '? PageNow = ". $ pageDown." '> next page </a> <br/> ";
}

// Click the button to return 10 pages
If ($ pageNow-10> 0 ){
Echo "<a href = '? PageNow = ". ($ pageNow-10)." '> </a> ";
}


// Pass the currently displayed page number to this page and display the page number button
For ($ I = 1; $ I <= $ pageCount; $ I ++ ){

If ($ I> $ pageNow-2 & $ I <$ pageNow + 6 ){
If ($ I! = $ PageNow ){
Echo "<a href = '? PageNow = ". $ I." '> page ". $ I." </a> ";
}
}
}

// Forward 10 pages
If ($ pageNow + 10 <= $ pageCount ){
Echo "<a href = '? PageNow = ". ($ pageNow + 10)." '>>>></a> ";
}

// Display the current page and the total number of pages
Echo "<br/> current page". $ pageNow. "Page/total". $ pageCount. "Page ";


// Jump to the page
Echo "Jump to: <input type = 'text' name = 'pagenow' id = 'pagenow' style = 'width: 30px; height: 20px '/> page <input type = 'submit' style = 'width: 37px; height: 20px; font-size: 11px; 'value = 'Go'/> ";
Echo "</form> ";
Echo "</div> ";
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.