gpt4 book ai didi

php - PHP MYSQL 表的分页

转载 作者:行者123 更新时间:2023-11-29 11:21:50 26 4
gpt4 key购买 nike

我想知道如何在这里插入表格的分页。正如您将看到的,它仍然是 MYSQL,它已经贬值了,因为它的所有者仍在工作并且不想更新。

我不是他的系统的开发者。你能帮我把这部分分页吗?我不熟悉旧的 mysql,因为我已经开始使用 MYSQLi

#TABLE

if ($userRow['type'] == 'ADMIN') {
$sql = "SELECT * FROM `complaints` ORDER BY `date_modify` DESC, `status` DESC LIMIT 60";

#country


} else {
$sql = "SELECT * FROM `complaints` WHERE `country` in (".$sqlp.") ORDER BY `date_modify` DESC, `status` DESC ";

}




if ($result=mysql_query($sql)) {
$query_num_rows = mysql_num_rows($result);


if($query_num_rows == 0){
echo "<script> alert('No Records Found, Please try again!')</script>";

} else {


while($row=mysql_fetch_array($result))

{
echo "<tbody><tr>";
if($userRow['type']=='ADMIN'){

echo "<td><a href=\"admin-update.php?id=".$row['id']."\">".$row['ticket']."</td>";

} else {

echo "<td><a href=\"followup.php?id=".$row['id']."\">".$row['ticket']."</td>";
}
echo "<td>".$row['c_Fname']." ".$row['c_Lname'];
echo "<td>".$row['section']."</td>";
echo "<td>".$row['topic']."</td>";
echo "<td>".$row['country']."</td>";
echo "<td>".$row['originator']."</td>";

echo "<td>".$row['current']."</td>";
echo "<td>".$row['date_open']."</td>";
echo "<td>".$row['date_modify']."</td>";

if ($row['status'] == 'OPEN') {
$date_o=$row['date_open'];
$date_today=date('Y-m-d h:i A');

$diff = strtotime($date_today) - strtotime($date_o);
$old = $diff/(60*60*24);

echo "<td>".floor($old)."</td>";

} else {

echo "<td> --- </td>";
}





echo "<td>".$row['status']."</td>";

}
}
}

?>

谢谢。

最佳答案

您需要在查询中处理offsetlimit:

SELECT column FROM table
LIMIT 10 OFFSET 10

通过GET传递一个名为page的变量:

HTML

<a href="URL?page=2">Page 2</a>

PHP

"SELECT * FROM complaints
LIMIT 10 OFFSET " . (intval($_GET['page'])-1) * 10

Page 1 => Records between 0 and 10

Page 2 => Records between 11 and 20

Page 3 => Records between 21 and 30

[...]

在第 2 页,您将获得 11 到 20 条之间的记录。

关于php - PHP MYSQL 表的分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38786223/

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