• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 795
  • Last Modified:

PHP Paging

hi guys,
we use a paging script to devide the pages and givem page numbers.
we use a while loop to for example return 10 results and then the next 10 would go on the next page,
we use this code " <?=$rs->getPageNav("id=$id")?> " on our page to call the navigation system...
the problem with it is that the number of pages has increased and now it goes to the second row of numbers.
example:

1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - 15

how can i get it to only show lest say 10 numbers only?
example:

1 - 2 - 3 - 4 - 5 - 6 - 8 - 9  ... 15

bellow is the code we use!
thank you :)
---------------------------------------------
paging.php

<?php
class MySQLPagedResultSet
{

  var $results;
  var $pageSize;
  var $page;
  var $row;
 
  function MySQLPagedResultSet($query,$pageSize,$cnx)
  {
    $resultpage = $_GET['resultpage'];
   
    $this->results = @mysql_query($query,$cnx);
    $this->pageSize = $pageSize;
    if ((int)$resultpage <= 0) $resultpage = 1;
    if ($resultpage > $this->getNumPages())
      $resultpage = $this->getNumPages();
    $this->setPageNum($resultpage);
  }
 
  function getNumPages()
  {
    if (!$this->results) return FALSE;
   
    return ceil(mysql_num_rows($this->results) /
                (float)$this->pageSize);
  }
 
  function setPageNum($pageNum)
  {
    if ($pageNum > $this->getNumPages() or
        $pageNum <= 0) return FALSE;
 
    $this->page = $pageNum;
    $this->row = 0;
    mysql_data_seek($this->results,($pageNum-1) * $this->pageSize);
  }
 
  function getPageNum()
  {
    return $this->page;
  }
 
  function isLastPage()
  {
    return ($this->page >= $this->getNumPages());
  }
 
  function isFirstPage()
  {
    return ($this->page <= 1);
  }
 
  function fetchArray()
  {
    if (!$this->results) return FALSE;
    if ($this->row >= $this->pageSize) return FALSE;
    $this->row++;
    return mysql_fetch_array($this->results);
  }
 
  function getPageNav($queryvars = '')
  {
  $nav = '';

    if (!$this->isFirstPage())
           {
           $nav .= "<a href=\"?resultpage=".
         ($this->getPageNum()-1).'&'.$queryvars.'">&nbsp;&nbsp;Prev&nbsp;&nbsp;</a>&nbsp;';
                }       
             
      if ($this->getNumPages() > 1)
      for ($i=1; $i<=$this->getNumPages(); $i++)
      {
   // Active
        if ($i==$this->page)
           $nav .= "&nbsp;$i&nbsp;&nbsp;";
        
   //numbers
       else
      $nav .= "<a href=\"?resultpage={$i}&".$queryvars."\">&nbsp;$i&nbsp;</a> ";
      }
           //previous
        
      
        //next    

    if (!$this->isLastPage())
    {
      $nav .= "<a href=\"?resultpage=".
              ($this->getPageNum()+1).'&'.$queryvars.'">&nbsp;&nbsp;Next&nbsp;&nbsp;</a> ';
    }
   
    return $nav;
  }
}
  ?>
-------------------------------------------
0
djsoltan
Asked:
djsoltan
  • 2
1 Solution
 
hernst42Commented:
Have a look at http:Q_22511146.html

$numpages =20;
$page =10;

$ingap = false;
for ($i = 1; $i <= $numpages; $i++)
{
      if (
      $i <= 3 ||  // 1st 3 pages
      $i > ($numpages -3) || // last 3 pages
      abs($page - $i) < 3 // show 3 pages around the current displayed page
      ) {
            $ingap = false;
            echo " | ";
            if ($i == $page) {
                  echo $i;
            } else {
                  echo "*$i*";
            }
      } else if (!$ingap) {
            $ingap = true;
            echo " | ... ";
      }
}
echo " |";

output is (as the link you posted does):
| *1* | *2* | *3* | ...  | *8* | *9* | 10 | *11* | *12* | ...  | *18* | *19* | *20* |

0
 
djsoltanAuthor Commented:
hi,
thanks for the info you provided however,,, i am not really a programmer and i didnt quite underestand what i need to do.... is it possible to add a line or edit one of the lines from the code i provided to accomplish this?
thank you :)
0
 
djsoltanAuthor Commented:
any help guys? :-s
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now