troubleshooting Question

PHP Paging

Avatar of djsoltan
djsoltan asked on
PHP
3 Comments1 Solution831 ViewsLast Modified:
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;
  }
}
  ?>
-------------------------------------------
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros