您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關使用php怎么實現一個后臺表格分頁功能,文章內容質量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。
具體如下:
<?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 //用戶管理 echo "用戶管理<br/>"; @$start = $_REQUEST['start']; if($start === null || $start === " "){ die("start required"); } require("init.php"); $sql = "SELECT * FROM xz_user LIMIT $start,$pagecount"; $sql1 = "SELECT uid FROM xz_user"; $result = mysqli_query($conn,$sql); $result1 = mysqli_query($conn,$sql1); if($result === false || $result1 === false) { echo "執行失敗"; }else { //$rowcount = mysqli_affected_rows($conn); $arr = mysqli_fetch_all($result,1); $rowcount = count($arr); echo "查詢到的結果行數:" . $rowcount . "<br/>"; //if($rowcount > 0){ $arr1 = mysqli_fetch_all($result1,1); $count = count($arr1); echo "總行數:$count<br/>"; ?> <table border="1"> <tr> <td>用戶編號</td> <td>用戶名</td> <td>密碼</td> <td>郵箱</td> <td>電話</td> <td>操作</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."'>刪除</a></td> </tr> "; } ?> </table> <?php } ?> <!-- 傳值 AJAX可優化 --> <a href="user.php?start=0" rel="external nofollow" >首頁</a> <a href="user.php?start=<?php if($start>=3)echo $start-3; else echo $start; ?>" rel="external nofollow" >上頁</a> <a href="user.php?start=3" rel="external nofollow" >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" >下頁</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" >尾頁</a> <span>第<?php echo $start/$pagecount+1 ?>頁|共<?php $tmp=$count/$pagecount; $tmp1=(int)($count/$pagecount); if($tmp>$tmp1) echo $tmp1+1; else echo $tmp1; ?>頁</span>
delete.php:
<?php //刪除用戶 echo "刪除用戶<br/>"; @$uid = $_REQUEST['uid']; if($uid === null || $uid === " "){ //這里注意,是|| die("uid required"); } require('init.php'); $sql = "DELETE FROM xz_user WHERE uid='$uid'"; $sql1 = "UPDATE xz_user SET uid=uid-1 WHERE uid > '$uid'"; $result = mysqli_query($conn,$sql); if($result === false){ echo "執行失敗"; }else{ $count = mysqli_affected_rows($conn); if($count > 0){ echo "用戶刪除成功"; $result1= mysqli_query($conn,$sql1); if($result1 === false){ echo "重排序失敗"; }else{ echo "重排序成功"; } 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 "要刪除的用戶不存在"; } } ?>
關于使用php怎么實現一個后臺表格分頁功能就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。