This paper describes the implementation of the PHP background table paging function. Share to everyone for your reference, as follows:
<?php //init.php $conn = mysqli_connect (' 127.0.0.1 ', ' root ', ', ' XZ ', 3306); $sql = "SET NAMES UTF8"; Mysqli_query ($conn, $sql); $pagecount = 3;? >
user.php:
<?php//user management echo "user Management <br/>"; @ $start = $_request[' start ']; if ($start = = = NULL | | $start = = = "") {die ("start required"); } require ("init.php"); $sql = "SELECT * from Xz_user LIMIT $start, $pagecount"; $sql 1 = "Select UID from Xz_user"; $result = Mysqli_query ($conn, $sql); $result 1 = mysqli_query ($conn, $sql 1); if ($result = = = False | | $result 1 = = = False) {echo "Failed to execute"; }else {//$rowcount = Mysqli_affected_rows ($conn); $arr = Mysqli_fetch_all ($result, 1); $rowcount = count ($arr); echo "Query result rows:". $rowcount. "<br/>"; if ($rowcount > 0) {$arr 1 = mysqli_fetch_all ($result); $count = count ($arr 1); echo "Total number of rows: $count <br/>";? ><table border= "1" > <tr> <td> User number </td> <td> user name </td> <td> password </TD&G T <td> email </td> <td> phone </td> <td> action </td> </tr><?php for ($i =0; $i <count ($ ARR), $i + +) {$tmp = $arr [$i] [UID]; echo " <tr> <td> ". $arr [$i] [' uid ']." </td> <td> ". $arr [$i] [' uname ']." </td> <td> ". $arr [$i] [' upwd ']." </td> <td> ". $arr [$i] [' email ']." </td> <td> ". $arr [$i] [' phone ']." </td> <td><a href= ' delete.php?uid= '. $tmp. "' > Delete </a></td> </tr> "; }?></table><?php}?><!--value Ajax optimized--><a href= "user.php?start=0" rel= "External nofollow" > Home </a><a href= "user.php?start=<?php if ($start >=3) echo $start-3; else echo $start;?> "rel=" external nofollow "> on page </a><a href=" user.php?start=3 "rel=" External nofollow "& Gt;2</a><a href= "user.php?start=6" rel= "external nofollow" >3</a><a href= "user.php?start=9" rel = "External nofollow" >4</a><a href= "user.php?start=12" rel= "external nofollow" >5</a><a href= "User.php?start=15" rel= "external nofollow" >6</a><a href= "User.php?start=<?php echo $start +3;?> "rel=" external nofollow "> Next </a><a href=" user.php?start=<?php if ($ Count%3==1) echo $count-1; ElseIf ($count%3==2) echo $count-2; ElseIf ($count%3==0) echo $count-3;?> "rel=" External nofollow "> Last </a><span> <?php echo $start/$ Pagecount+1?> Page | total <?php $tmp = $count/$pagecount; $tmp 1= (int) ($count/$pagecount); if ($tmp > $tmp 1) echo $tmp; else echo $tmp 1;?> page </span>
delete.php:
<?php //delete user echo "delete user <br/>"; @ $uid = $_request[' uid ']; if ($uid = = = NULL | | $uid = = = "") { //note here, yes | | Die ("uid required"); } Require (' init.php '); $sql = "DELETE from Xz_user WHERE uid= ' $uid '"; $sql 1 = "UPDATE xz_user SET uid=uid-1 WHERE uid > ' $uid '"; $result = Mysqli_query ($conn, $sql); if ($result = = = False) { echo "execution failed"; } else{ $count = mysqli_affected_rows ($conn); if ($count > 0) { echo "user deletion succeeded"; $result 1= mysqli_query ($conn, $sql 1); if ($result 1 = = = False) { echo "reorder failed"; } else{ echo "reordering succeeded"; } if ($uid% $pagecount = = 0) Header ("location:user.php?start= $uid"); if ($uid% $pagecount = = 1) { $uid-= 1; Header ("location:user.php?start= $uid"); } if ($uid% $pagecount = = 2) { $uid-= 2; Header ("location:user.php?start= $uid"); } } else{ echo "The user to delete does not exist"; } ? >
Note:
(1) Using AJAX can realize the value optimization, improve performance, there is no implementation;
(2) Next page There are not some bugs, not to the last page to stop, follow-up to achieve it.