Link to home
Start Free TrialLog in
Avatar of djsoltan
djsoltan

asked on

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;
  }
}
  ?>
-------------------------------------------
ASKER CERTIFIED SOLUTION
Avatar of hernst42
hernst42
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of djsoltan
djsoltan

ASKER

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 :)
any help guys? :-s