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($resultp age);
}
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->res ults,($pag eNum-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->r esults);
}
function getPageNav($queryvars = '')
{
$nav = '';
if (!$this->isFirstPage())
{
$nav .= "<a href=\"?resultpage=".
($this->getPageNum()-1).'& '.$queryva rs.'">&nbs p; Pr ev &n bsp;</a>&n bsp;';
}
if ($this->getNumPages() > 1)
for ($i=1; $i<=$this->getNumPages(); $i++)
{
// Active
if ($i==$this->page)
$nav .= " $i ";
//numbers
else
$nav .= "<a href=\"?resultpage={$i}&". $queryvars ."\">  ;$i < /a> ";
}
//previous
//next
if (!$this->isLastPage())
{
$nav .= "<a href=\"?resultpage=".
($this->getPageNum()+1).'& '.$queryva rs.'">&nbs p; Ne xt &n bsp;</a> ';
}
return $nav;
}
}
?>
-------------------------- ---------- -------
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
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
{
$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($resultp
}
function getNumPages()
{
if (!$this->results) return FALSE;
return ceil(mysql_num_rows($this-
(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->res
}
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->r
}
function getPageNav($queryvars = '')
{
$nav = '';
if (!$this->isFirstPage())
{
$nav .= "<a href=\"?resultpage=".
($this->getPageNum()-1).'&
}
if ($this->getNumPages() > 1)
for ($i=1; $i<=$this->getNumPages(); $i++)
{
// Active
if ($i==$this->page)
$nav .= " $i ";
//numbers
else
$nav .= "<a href=\"?resultpage={$i}&".
}
//previous
//next
if (!$this->isLastPage())
{
$nav .= "<a href=\"?resultpage=".
($this->getPageNum()+1).'&
}
return $nav;
}
}
?>
--------------------------
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
any help guys? :-s
ASKER
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 :)