【发布时间】:2019-10-11 09:11:51
【问题描述】:
我已经处理了两天多的问题,但仍然找不到问题所在。我正在尝试为我的搜索结果构建一个分页系统。当我在新的 php 文件中运行代码时,代码工作得非常好,但是当我在表格中显示这些结果时,我不断收到该错误!最后一个 else 部分内的消息。另外,无论我在哪里放置页码的循环,它总是显示在表格之前。想想我忙于处理这个问题,我正专注于同一点。请帮忙!
edit 我刚刚删除了所有条件语句,并为我通过 POST 方法获得的所有变量获得了未定义的索引。这就是问题所在,但仍然不知道有什么解决方案。
<?php
if (isset($_POST['search_btn'])) {
include_once "db_connect.php";
$from = $_POST['from'];
$where = $_POST['where'];
$date = $_POST['date'];
$type = $_POST['type'];
$proc_id = $_POST['proc_id'];
if(empty($from) || empty($where) || empty($date) || empty($type)){
header("Location: index.php?search=empty");
exit();
}else{
//define how many results you want per page
$results_per_page = 10;
//number of results stored in database
"SELECT * FROM proc WHERE p_from = '".$from."' and p_where = '".$where."' and type= '".$type."' ";
$result = mysqli_query($conn, $sql);
$number_of_results = mysqli_num_rows($result);
//determine number of total pages available
$number_of_pages = ceil($number_of_results/$results_per_page);
//determine which page number visitor is currently on
if (!isset($_GET['page'])) {
$page = 1;
} else {
$page = $_GET['page'];
}
//determine the SQL LIMIT starting number for the result on the displaying page
$this_page_first_result = ($page-1)*$results_per_page;
//retrive selected results from database and display them on page $sql='SELECT * FROM proc LIMIT ' . $this_page_first_result . ',' . $results_per_page;
$result = mysqli_query($conn, $sql);
while($rows = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
echo '<tr onclick="content(\''. $rows['proc_id'] .'\')">';
echo "<td>" .$rows['p_name'] . " " . $rows['p_surname']. " </td>";
echo "<td>" .$rows['p_from']. "</td>";
echo "<td>" .$rows['p_where']. "</td>";
echo "<td>" .$rows['p_date']. "</td>";
echo "<td>" .$rows['price']. "</td>";
echo "<td>" .$rows['type']. "</td>";
echo "</tr>";
}
}
//display the links to the pages
for ($page=1;$page<=$number_of_pages;$page++) {
echo '<a href="search.php?page=' . $page . '">' . $page . '</a> ';
}
}else{
echo "Error!";
}
?>
【问题讨论】:
标签: php html css pagination