001
<? Php
002
// The session set on the login page. When the session contains the name
003
// Session_start ();
004
// $ Name = $ _ SESSION ['name'];
005
// If (empty ($ name )){
006
// Header ("Location: error. php ");
007
// Exit ();
008
//}
009
010
// Process-oriented, data Paging
011
If (false! = ($ Mysql = mysql_connect ('local mysql', 'mysql username', 'mysql password '))){
012
Mysql_query ('set names utf8', $ mysql); // sets the encoding in the database.
013
Mysql_select_db ("database", $ mysql );
014
} Else {
015
Die ("connection failed ");
016
}
017
018
019
$ PageSize = 10; // number of entries displayed on the page
020
$ RowCount = 0; // The total number of data records, obtained from the database
021
022
$ SqlCount = 'select count (id) from employee ';
023
$ Res1 = mysql_query ($ sqlCount, $ mysql );
024
025
// Retrieve the number of data entries
026
If (false! = ($ Row = mysql_fetch_row ($ res1 ))){
027
$ RowCount = $ row [0];
028
}
029
030
// The total number of pages, calculated
031
$ PageCount = 0;
032
$ PageCount = ceil ($ rowCount/$ pageSize );
033
034
// Obtain the current page
035
If (! Isset ($ _ GET ['pagenow']) {// if get/post is empty, the default value is 1.
036
$ PageNow = 1; // current page number
037
} Elseif (false! = Is_numeric ($ _ GET ['pagenow']) {
038
$ PageNow = $ _ GET ['pagenow'];
039
} Else {
040
Header ("Location: ../Error/error. php ");
041
Exit ();
042
}
043
044
// Print the paging data
045
Echo "<div style = 'margin-left: 300px; margin-top: 1px; '> ";
046
Echo "<table style = 'border: 1px; border-style: solid; border-width: 1px; border-color: green'> ";
047
Echo "<tr> <th> id </th> & nbsp; <th> name </th> & nbsp; <th> age </th> & nbsp; <th> sex </th> & nbsp; <th> birthday </th> & nbsp; <th> edit employee </th> & nbsp; <th> delete an employee </th> & nbsp; </tr> ";
048
$ SqList = "select id, name, age, sex, birthday from employee limit". ($ pageNow-1) * $ pageSize. ",". $ pageSize;
049
$ Res2 = mysql_query ($ sqList, $ mysql );
050
While (false! = ($ Row = mysql_fetch_assoc ($ res2 ))){
051
Echo "<tr> <td >{$ row ['id']} </td> & nbsp; <td >{$ row ['name']} </td> & nbsp; <td >{$ row ['age']} </td> & nbsp; <td >{$ row ['sex']} </td> & nbsp; <td >{$ row ['birthday']} </td> & nbsp; <td> <a href = #> edit </a> </td> & nbsp; <td> <a href = #> Delete </a> </td> </tr> ";
052
}
053
Echo "</table> ";
054
055
// Control the number of pages displayed in the form
056
Echo "<form action = 'current page'> ";
057
// Previous page button
058
If ($ pageNow> 1 ){
059
$ PageUp = $ pageNow-1;
060
Echo "<a href = '? PageNow = ". $ pageUp." '> previous page </a> & nbsp ;";
061
}
062
063
// Next page button
064
If ($ pageNow <$ pageCount ){
065
$ PageDown = $ pageNow + 1;
066
Echo "<a href = '? PageNow = ". $ pageDown." '> next page </a> & nbsp; <br/> ";
067
}
068
069
// Click the button to return 10 pages
070
If ($ pageNow-10> 0 ){
071
Echo "<a href = '? PageNow = ". ($ pageNow-10)." '> & lt; </a> & nbsp ;";
072
}
073
074
075
// Pass the currently displayed page number to this page and display the page number button
076
For ($ I = 1; $ I <= $ pageCount; $ I ++ ){
077
078
If ($ I> $ pageNow-2 & $ I <$ pageNow + 6 ){
079
If ($ I! = $ PageNow ){
080
Echo "<a href = '? PageNow = ". $ I." '> page ". $ I." </a> & nbsp ;";
081
}
082
}
083
}
084
085
// Forward 10 pages
086
If ($ pageNow + 10 <= $ pageCount ){
087
Echo "<a href = '? PageNow = ". ($ pageNow + 10)." '> & gt; </a> & nbsp ;";
088
}
089
090
// Display the current page and the total number of pages
091
Echo "<br/> current page". $ pageNow. "Page/total". $ pageCount. "Page ";
092
093
094
// Jump to the page
095
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'/> ";
096
Echo "</form>"; www.2cto.com
097
Echo "</div> ";
098
099
100
?>
Author: too much yogurt to drink