php - 使用 php 分页

标签 php javascript mysql html

在下面的代码中,我试图在一页上显示 10 个产品的详细信息,然后在下一页显示其他产品的详细信息。问题是当我点击底部的第 2 页链接时,它给出了“请选择类别”的错误消息。请帮助我我的代码中的问题在哪里。

 $SQLstring = "SELECT product_id FROM products LIMIT $offset,$rowsperpage";    
echo "<table border='1' width=500 ><tr><th>Product ID</th>tr>"; 

    while ($Row = mysqli_fetch_assoc($QueryResult))
             {
              $productid = $Row['product_id'];
         echo "<tr><td>$productid</td></tr>";
 }

    echo "</table>"; 
    $range = 3;
   if ($currentpage > 1)
     {  
    echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";   
    $prevpage = $currentpage - 1;   
    echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
    } 
  for ($x = ($currentpage - $range);$x < (($currentpage + $range) + 1); $x++) 
    {   
     if (($x > 0) && ($x <= $totalpages)) 
    {
    if ($x == $currentpage) 
   {
   echo " [<b>$x</b>] ";  
   } 
   else 
    {     
  echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";      
     }}}                

    mysqli_close($DBConnect);
}

最佳答案

你的问题是:

$category=$_POST["categor"];

有人点击链接后,$_POST["categor"] 将为空。尝试 $_REQUEST["categor"] 并像这样创建链接:

echo " <a href='{$_SERVER['PHP_SELF']}?category=".$category."&currentpage=1'><<</a> "; 

echo " <a href='{$_SERVER['PHP_SELF']}?category=".$category."&currentpage=$prevpage'><</a> ";

这样做你可以使用 POST 和 GET。

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

相关文章:

html - 将用户输入从 HTML 页面传递到 Perl 脚本并在网页中显示结果

MySQL连接表两次而不重复数据

mysql - 如何将三个 MySQL 查询合并为一个?

php - 实现自动提示的方法

php - 在 PHP 中合并 2 个对象数组

php - 拉拉维尔 : Install Microsoft Azure Client Library with composer

javascript - 这个错误是什么意思——Uncaught TypeError : Already read?

javascript - 错误 "google.charts.load() cannot be called more than once with version .45 or earlier"

php - 为每次注册创建一个新数据库,是否有可能 Laravel 5

javascript - 重定向到带有发布数据的 div