分页后第1页没有显示任何结果

时间:2014-07-01 20:10:52

标签: php jquery pagination

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

任何人都可以看到问题所在吗?

感谢您寻找.............

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>";
         }
      }
   }

1 个答案:

答案 0 :(得分:2)

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

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

应该是

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