我需要有关其分页的网站帮助。
这是它的工作方式,我搜索了一个查询,我的页面给了我它的结果。到目前为止,一切都很好,但是每当我单击下一页(例如第2页)时,它都不会将我定向到下一页,而是会给我一个错误:
注意:未定义的变量:第72行的C:\ xampp \ htdocs \ intern \ view-paginated.php中的valueToSearch
我的第一个搜索查询有效,但是只有当我单击下一页时,突然它才无法识别我的搜索查询,基本上我的分页无法正常工作。
==源代码==
获取搜索查询:
if(isset($_POST['search']))
{
$valueToSearch = $_POST['valueToSearch'];
// search in all table columns
// using concat mysql function
$query = "SELECT * FROM `orders` WHERE CONCAT(`KeyAccount`, `BatchNumber`, `Product`, `Quantity`, `PO`, `DateRequested`, `DateDelivered`, `Status`) LIKE '%".$valueToSearch."%'";
$search_result = filterTable($query);
}
else {
$query = "SELECT * FROM `orders`";
$search_result = filterTable($query);
}
// function to connect and execute the query
function filterTable($query)
{
$connect = mysqli_connect("localhost", "root", "", "test");
$filter_Result = mysqli_query($connect, $query);
return $filter_Result;
定义变量:
$result = mysql_query("SELECT * FROM `orders` WHERE CONCAT(`KeyAccount`, `BatchNumber`, `Product`, `Quantity`, `PO`, `DateRequested`, `DateDelivered`, `Status`) LIKE '%".$valueToSearch."%'");
$total_results = mysqli_num_rows($search_result);
$total_pages = ceil($total_results / $per_page);
最重要的是,显示分页:
echo "<b>View Page:</b> ";
for ($i = 1; $i <= $total_pages; $i++)
{
echo "<a href='view-paginated.php?page=$i'>$i</a> ";
}
结果显示:
echo "<tr>";
echo '<td>' . mysql_result($result, $i, 'KeyAccount') . '</td>';
echo '<td>'. mysql_result($result, $i, 'BatchNumber'). '</td>';
echo '<td>' . mysql_result($result, $i, 'Product') . '</td>';
echo '<td>' . mysql_result($result, $i, 'Quantity') . '</td>';
echo '<td>' . mysql_result($result, $i, 'PO') . '</td>';
echo '<td>' . mysql_result($result, $i, 'DateRequested') . '</td>';
echo '<td>' . mysql_result($result, $i, 'DateDelivered') . '</td>';
echo '<td>' . mysql_result($result, $i, 'Status') . '</td>';
echo '<td><a href="edit.php?id=' . mysql_result($result, $i, 'id') . '">Edit</a></td>';
echo "</tr>";
谢谢你。
答案 0 :(得分:1)
这是因为您使用POST来获取变量值,而使用GET来发送变量值 像这样:
if(isset($_POST['search']))
此外,您必须发送搜索参数,同时生成分页链接,如下所示:
for ($i = 1; $i <= $total_pages; $i++)
{
echo "<a href='view-paginated.php?page=$i".$i."&search=".$search.;
}