This is my paging class (can’t remember where i got it from but ive used it for years):
the mysql_data_seek is doing its job perfect but here is whats happening:
[url]http://www.knowj.com/photography/1/
as you can see no LIMIT is being passed into the query causing it to start from the right row but getting all the results rather than the limited amount.
How would i be able to build a LIMIT into this paging class without having to change all my SQL querys through out my site?
[code=php]
<?php
class paging extends database
{
var $pageSize;
var $page;
var $row;
function paging()
{
}
function paging_build($pageSize)
{
$resultpage = $_GET[‘resultpage’];
//run the mysql query
$this->execute();
$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;
//change the pointer to the new row and set $this->results to that value
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=”‘.preg_replace(“(/[0-9]+/)”, ”, $_SERVER[‘REQUEST_URI’]).’/’.($this->getPageNum()-1).’/”>Prev</a>’;
}
if ($this->getNumPages() > 1)
{
for ($i=1; $i<=$this->getNumPages(); $i++)
{
if ($i==$this->page)
{
$nav .= “$i “;
}
else
{
$nav .= ‘<a href=”‘.preg_replace(“(/[0-9]+/)”, ”, $_SERVER[‘REQUEST_URI’]).’/’.$i.’/”>’.$i.'</a>’;
}
}
if (!$this->isLastPage())
{
$nav .= ‘<a href=”‘.preg_replace(“(/[0-9]+/)”, ”, $_SERVER[‘REQUEST_URI’]).’/’.($this->getPageNum()+1).’/”>Next</a> ‘;
}
return $nav;
}
}
}
?>