分页只是改变页码而不是内容

时间:2017-01-10 20:03:45

标签: php html mysql

我有一个包含用户列表的表,我想为此表创建分页。

但是,当我点击第2页时,页面会更改,但不会更改users列表的内容。

<?php

session_start();

require_once "connect.php";

//Database connect
$database = @new mysqli($host, $db_user, $db_password, $db_name);

//Limit users
  $start = 0;
  $limit = 3;

//Question to -> Database
$sql = ("SELECT * FROM users LIMIT $start, $limit");
$adds = $database->query($sql);

//Return records
$rows = mysqli_num_rows($adds);

echo "Rows found in database.. ".$rows."<br /><br />";

if(isset($_GET['id']))
{
    $id=$_GET['id'];
    $start=($id-1)*$limit;
}
else{
    $id=1;
}

if ($rows >= 1)
{
  //the beginning of the table

echo<<<END
  <table width="1000" align="center" border="1" bordercolor="#d5d5d5"  cellpadding="0" cellspacing="0">
<tr>
  <td width="50" align="center" bgcolor="e5e5e5"></td>
  <td width="50" align="center" bgcolor="e5e5e5">IDUsera</td>
  <td width="20" align="center" bgcolor="e5e5e5">NazwaUsera</td>
  <td width="20" align="center" bgcolor="e5e5e5">EmailUsera</td>
  <td width="20" align="center" bgcolor="e5e5e5">DataRejestracji</td>
  <td width="20" align="center" bgcolor="e5e5e5">Indetyfikator grupy</td>
</tr>
<tr>
END;
}

  while($score = mysqli_fetch_assoc($adds)) {

      $row_score_id = $score['id'];
      $row_score_user = $score['user']."  ";
      $row_score_register = $score['dataRes']. "  ";

      //continued table
echo<<<END
  <td width="50" align="center"><a class="button_red" href="delete_user.php?id=''">Delete</a></td>
  <td width="50" align="center">$row_score_id</td>
  <td width="100" align="center">$row_score_user</td>
  <td width="100" align="center"></td>
  <td width="100" align="center">$row_score_register</td>
  <td width="100" align="center"></td>
</tr>
END;

  }

        $pagnSql = ("SELECT * FROM users");
        $pagnBase = $database->query($pagnSql);
        $pagnRows = mysqli_num_rows($pagnBase);
        $total=ceil($pagnRows/$limit);
        if($id>1)
        {
            //Go to previous page to show previous 10 items. If its in page 1 then it is inactive
            echo "<a href='?id=".($id-1)."' class='button'>PREVIOUS</a>";
        }
        if($id!=$total)
        {
            ////Go to previous page to show next 10 items.
            echo "<a href='?id=".($id+1)."' class='button'>NEXT</a>";
        }

        for($i=1;$i<=$total;$i++)
        {
            if($i==$id) { echo "<li class='current'>".$i."</li>"; }

            else { echo "<li><a href='?id=".$i."'>".$i."</a></li>"; }
        }
?>

1 个答案:

答案 0 :(得分:0)

你必须从GET开始$ start 改变这个   $ start = 0; 至:   $ start = $ _GET [id];