如何使用 MySQL 和 PHP 对多个搜索结果进行分页?
How to work on pagination for multiple search results using MySQL and PHP?
我正在从事网络搜索引擎项目。我正在研究分页功能。当我单击该页面时,它会给出突然的结果并给出 Undefined variable: page1 error
。怎么办?
if(isset($_GET['page'])) //results displayed based on page selection
{
$page=$_GET['page'];
if($page=="" || $page=="1")
{
$page1=0;
}
else
{
$page1=($page*10)-10;
}
}
$numrows1 = mysqli_num_rows($query); // page evaluation and this statement calculates number of resultant rows
$a = $numrows1/10; //10 is for number of results per page and $a gives number of pages
$a = ceil($a);
echo "<br>"; echo "<br>";
for($b=1; $b<=$a; $b++)
{
?><a href="search.php?page=<?php echo $b; ?>" style="text-decoration:none;"><?php echo $b." ";?></a><?php
}
希望我说清楚了。谁能帮我解决这个问题?
除非您在 URI 中有一个页面,否则您似乎永远不会设置该页面。
我假设如果您使用 "page.php?page=1" 它不会抛出该错误,因为将设置 $page1。
我个人会这样做:
if(isset($_GET['page']) && $_GET['page'] != 1)//if page is set and page doesn't equal 1
{
$startingRecord = ($_GET['page'] * 10) - 10;
}
else
{
$startingRecord = 0;
}
此外,我将 $page1
切换为 $startingRecord
以使其更有意义,因为您计算的是起始记录,而不是页面。
我正在从事网络搜索引擎项目。我正在研究分页功能。当我单击该页面时,它会给出突然的结果并给出 Undefined variable: page1 error
。怎么办?
if(isset($_GET['page'])) //results displayed based on page selection
{
$page=$_GET['page'];
if($page=="" || $page=="1")
{
$page1=0;
}
else
{
$page1=($page*10)-10;
}
}
$numrows1 = mysqli_num_rows($query); // page evaluation and this statement calculates number of resultant rows
$a = $numrows1/10; //10 is for number of results per page and $a gives number of pages
$a = ceil($a);
echo "<br>"; echo "<br>";
for($b=1; $b<=$a; $b++)
{
?><a href="search.php?page=<?php echo $b; ?>" style="text-decoration:none;"><?php echo $b." ";?></a><?php
}
希望我说清楚了。谁能帮我解决这个问题?
除非您在 URI 中有一个页面,否则您似乎永远不会设置该页面。
我假设如果您使用 "page.php?page=1" 它不会抛出该错误,因为将设置 $page1。
我个人会这样做:
if(isset($_GET['page']) && $_GET['page'] != 1)//if page is set and page doesn't equal 1
{
$startingRecord = ($_GET['page'] * 10) - 10;
}
else
{
$startingRecord = 0;
}
此外,我将 $page1
切换为 $startingRecord
以使其更有意义,因为您计算的是起始记录,而不是页面。