Php 页码在第1页后不显示任何结果

Php 页码在第1页后不显示任何结果,php,jquery,pagination,Php,Jquery,Pagination,我正在使用这个分页脚本,它显示了第一页的正确记录数和正确的页面链接数。但是,当我单击页面链接时,其他页面根本不显示任何记录或页面链接 有人能看出问题出在哪里吗 感谢您的关注 if(isset($_GET['brand'])){ $brand = $_GET['brand']; $sql = mysqli_query($link, "SELECT COUNT(id) FROM products WHERE brand = '$brand'

我正在使用这个分页脚本,它显示了第一页的正确记录数和正确的页面链接数。但是,当我单击页面链接时,其他页面根本不显示任何记录或页面链接

有人能看出问题出在哪里吗

感谢您的关注

if(isset($_GET['brand'])){
   $brand = $_GET['brand'];
   $sql = mysqli_query($link, "SELECT COUNT(id) FROM products WHERE brand = '$brand' 
                       AND status = 1 ORDER BY id DESC") OR die(mysqli_error($link));
   $r = mysqli_fetch_row($sql);
   $numrows = $r[0];
   // number of rows to show per page
   $rowsperpage = 1;
   // find out total pages
   $totalpages = ceil($numrows / $rowsperpage);
   // get the current page or set a default
   if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
   // cast var as int
   $currentpage = (int) $_GET['currentpage'];} 
   else {
   // default page num
   $currentpage = 1;} // end if
   if ($currentpage > $totalpages) {
   $currentpage = $totalpages;} // end if
   // if current page is less than first page...
   if ($currentpage < 1) {
      $currentpage = 1;} // end if
      $offset = ($currentpage - 1) * $rowsperpage;
      // get the info from the db 
      $sql = mysqli_query($link, "SELECT *FROM products WHERE  brand = '$brand' AND 
                          status 1 ORDER BY id DESC LIMIT $offset, $rowsperpage") OR 
                        die(mysqli_error($link));
      echo"<div class='brandheading'>",
      $brand,
      "</div>";
      if (!mysqli_num_rows($sql)){
         echo 'No Products Match That Brand';}
      else{
         /******  build the pagination links ******/
         echo" <div class='pagination'>";
         // range of num links to show
         $range = 3;
         // if not on page 1, don't show back links
         if ($currentpage > 1) {
            // show << link to go back to page 1
            echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
            // get previous page num
            $prevpage = $currentpage - 1;
            // show < link to go back to 1 page
            echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
         } // end if 
         // loop to show links to range of pages around current page
         for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
            // if it's a valid page number...
            if (($x > 0) && ($x <= $totalpages)) {
               // if we're on current page...
               if ($x == $currentpage) {
                  // 'highlight' it but don't make a link
                  echo " [<b>$x</b>] ";
                  // if not current page...
               } 
               else {
                  // make it a link
                   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
               } // end else
            } // end if 
         } // end for
         // if not on last page, show forward and last page links        
         if ($currentpage != $totalpages) {
            // get next page
            $nextpage = $currentpage + 1;
            // echo forward link for next page 
            echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
            // echo forward link for lastpage
            echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
         } // end if
         /****** end build pagination links ******/
         echo"</div>";
         while($row = mysqli_fetch_array($sql)){
            $data = $row['image'];
            $file = substr($data, strpos($data, "/") + 1);
            echo "<div class='featuredproduct'>",
            "<a class='featuredlink' href='products.php?product=" . $row['id'] . "'>",
            "<div class='productimage'>",
            "<img class='featuredproductimage' src='$file' alt='{$row['name']} Image' 
              />",
            "</div>",
            "<div class='featuredproductname'>{$row['name']}</div>",
            "<div class='featuredproductprice'>&pound{$row['price']}</div>",
            "</a>",
            "</div>";
         }
      }
   }

当进入下一页和/或上一页时,您没有通过该品牌

echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
应该是

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

在我深入讨论这个问题之前,我必须评论一下:缩进是非常重要的。这不仅是最佳实践,而且有助于调试这些情况。对不起,我将编辑这篇文章!首先,您是否在html中确认了HREF是正确的?其次,您是否手动运行SQL查询以确认它收回了有效的响应?我接受了下面@Nawed Khan的答案。这只是一个没有将品牌发送到下一页的案例!谢谢你的帮助,Guysah,非常感谢!现在就这样了!