Php “下一步”按钮不会刷新包含下一步25个结果的页面
我有下面的代码,正在尝试从我的sql表中获取下25个结果,以显示在第页上。但是,无论何时单击“下一步”按钮,都不会显示任何信息。我有我的偏移量=$page-1*$items\u per\u page……我很难弄明白这一点,因为与我编写的其他代码相比,它似乎很简单,但事实证明对我来说非常难以捉摸……任何帮助都将不胜感激。我的主要问题是,下一个链接没有提供下一个25个结果,我无法确定为什么以及如何更正Php “下一步”按钮不会刷新包含下一步25个结果的页面,php,sql,Php,Sql,我有下面的代码,正在尝试从我的sql表中获取下25个结果,以显示在第页上。但是,无论何时单击“下一步”按钮,都不会显示任何信息。我有我的偏移量=$page-1*$items\u per\u page……我很难弄明白这一点,因为与我编写的其他代码相比,它似乎很简单,但事实证明对我来说非常难以捉摸……任何帮助都将不胜感激。我的主要问题是,下一个链接没有提供下一个25个结果,我无法确定为什么以及如何更正 echo "<h3 style='t
echo "<h3 style='text-align:center;'>Welcome to the Exchange Portal, " . $row['name'] . "! </h3>";
$items_per_page = 25;
$sql_count = "SELECT pin, title, title2, email, phone FROM crown_acura";
$result_cnt = mysqli_query($conn, $sql_count);
if(false === $result_cnt) {
throw new Exception('Query failed with: ' . mysqli_error());
} else {
$row_count = mysqli_num_rows($result_cnt);
// free the result set as you don't need it anymore
//mysqli_free_result($result_cnt);
}
echo $row_count;
echo " ";
if (!isset($_GET['Page'])) {
$Page = 1;
} else {
$Page = $_GET['Page'];
}
echo $page;
echo " ";
$page_count = 0;
if (0 === $row_count) {
// maybe show some error since there is nothing in your table
} else {
// determine page_count
$page_count = (int)ceil($row_count / $items_per_page);
// double check that request page is in range
if($page > $page_count) {
// error to user, maybe set page to 1
$page = 1;
}
}
echo " ";
echo $page_count;
echo " ";
echo $items_per_page;
$offset = ($page-1)*$items_per_page;
//echo $paging_info;
//echo " ";
echo "<br />";
//Query for displaying results
$list_sql = "SELECT pin, title, title2, email, phone FROM crown_acura LIMIT $offset, $items_per_page";
$result_query = $conn->query($list_sql);
//Table for displaying query results
echo "<table class='verify'>";
echo "<tr >";
echo "<td><h3>Name</h3></td><td> </td><td><h3>E-mail</h3></td><td><h3>Phone</h3></td>";
echo "</tr>";
for($i = 1; $i<= $page_count; $i++) {
if ($result_query->num_rows > 0) {
// output data of each row
while($row3 = mysqli_fetch_array($result_query)) {
echo "<tr>";
echo "<td class='dltd2 dlcl'>" . $row3["title"] . "</td><td>" . $row3["title2"] . "</td><td><a href='mailto:" . $row3['email'] . "'>" . $row3["email"] . "</a> </td><td>" . $row3["phone"] . " </td>";
echo "</tr>";
}
} else {
echo "0 results";
}
}
echo "<tr></tr>";
$next_page = $page + 1;
$last_page = $page - 1;
if($paging_info['curr_page'] <= 1) {
echo "<tr>";
echo "<td></td><td colspan='2'><a class='loadlink' href='" . $_PHP_SELF . "'>Next 25</a></td><td></td>";
echo "</tr>";
} elseif ($paging_info['curr_page'] < $page_count) {
echo "<tr>";
echo "<td></td><td><a href='" . $_PHP_SELF . "?page=" . $last_page . "'>Prev 25</a></td><td><a href='" . $_PHP_SELF . "?page=" . $next_page . "'>Next 25</a></td><td></td>";
echo "</tr>";
} elseif ($paging_info['curr_page'] === $page_count) {
echo "<tr>";
echo "<td></td><td colspan='2'><a href='" . $_PHP_SELF . "?page=" . $last_page . "'>Prev 25</a></td><td></td>";
echo "</tr>";
}
echo "</table>";
}
}
}
您是否尝试运行呈现的SQL 输出到浏览器:
"SELECT pin, title, title2, email, phone FROM crown_acura LIMIT $offset, $items_per_page"
试试这个。。。并将$page更改为不同的值2,3,…,等等
<?php
$items_per_page = 25;
$sql_count = "SELECT pin, title, title2, email, phone FROM crown_acura";
$result_cnt = mysqli_query($conn, $sql_count);
if (false === $result_cnt) {
throw new Exception('Query failed with: ' . mysqli_error());
} else {
$row_count = mysqli_num_rows($result_cnt);
// free the result set as you don't need it anymore
//mysqli_free_result($result_cnt);
}
echo $row_count;
echo " ";
if (!isset($_GET['Page'])) {
$Page = 1;
} else {
$Page = $_GET['Page'];
}
echo $page;
echo " ";
$page_count = 0;
if (0 === $row_count) {
// maybe show some error since there is nothing in your table
} else {
// determine page_count
$page_count = (int)ceil($row_count / $items_per_page);
// double check that request page is in range
if ($page > $page_count) {
// error to user, maybe set page to 1
$page = 1;
}
}
echo " ";
echo $page_count;
echo " ";
echo $items_per_page;
$offset = ($page - 1) * $items_per_page;
//echo $paging_info;
//echo " ";
echo "<br />";
//Query for displaying results
$list_sql = "SELECT pin, title, title2, email, phone FROM crown_acura LIMIT $offset, $items_per_page";
$result_query = $conn->query($list_sql);
echo ("RESULTS: ".$result_query->num_rows());
?>对于$i=1,您的for循环的目的是什么$我不完全确定……你没提过。出于教育目的,写一篇描述你认为你的代码工作的原因、与原始代码相比你改变了什么或者OP的错误在哪里的文章总是一个好主意。你能进一步说明吗?我的查询实际上是在显示请求的信息时运行的,如果我手动更改$offset变量的值,则将其限制在前25个或下25个。echo$list\u sql-查看发送到MYSQL的内容。选择pin、标题、标题2、电子邮件、电话FROM crown\u acura LIMIT 0,25-这是当我回显$list_sqlI时在页面上显示的内容。我觉得当您单击“下一步”25时,这应该会以某种方式更改$offset=25,并在同一页面上重新运行查询……但我不知道如何实现这一点……并且应该更改$page=2。。。。。。