gpt4 book ai didi

php - 分页只是改变页码,不改变内容

转载 作者:行者123 更新时间:2023-11-29 19:35:33 24 4
gpt4 key购买 nike

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

但是,当我单击第 2 页时,页面会发生变化,但用户列表的内容不会发生变化。

<?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>"; }
}
?>

最佳答案

您必须将 $start 从 GET 中放入改变这个 $开始= 0;到: $start = $_GET[id];

关于php - 分页只是改变页码,不改变内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41577394/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com