溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

使用php怎么實(shí)現(xiàn)一個(gè)后臺(tái)表格分頁功能

發(fā)布時(shí)間:2021-04-15 16:16:44 來源:億速云 閱讀:153 作者:Leah 欄目:開發(fā)技術(shù)

這篇文章將為大家詳細(xì)講解有關(guān)使用php怎么實(shí)現(xiàn)一個(gè)后臺(tái)表格分頁功能,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。

具體如下:

<?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 "執(zhí)行失敗";
  }else {
    //$rowcount = mysqli_affected_rows($conn);
    $arr = mysqli_fetch_all($result,1);
    $rowcount = count($arr);
    echo "查詢到的結(jié)果行數(shù):" . $rowcount . "<br/>";
    //if($rowcount > 0){
      $arr1 = mysqli_fetch_all($result1,1);
      $count = count($arr1);
      echo "總行數(shù):$count<br/>";
?>
<table border="1">
  <tr>
    <td>用戶編號(hào)</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可優(yōu)化 -->
<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 "執(zhí)行失敗";
  }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 "要?jiǎng)h除的用戶不存在";
    }
  }
?>

關(guān)于使用php怎么實(shí)現(xiàn)一個(gè)后臺(tái)表格分頁功能就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

php
AI