page = $_GET['screen'] : $this->page = 1;
$this->url = $url;
$this->num = $num;
$this->num_rows = mysql_num_rows(mysql_query($query));
$this->pages = ceil($this->num_rows / $this->num);
$this->start = ($this->page - 1) * $this->num;
$this->query = "$query LIMIT $this->start, $this->num";
}
// Use $p->getFirst() to return a link which will bring you to the first page.
function getFirst()
{
if ($this->page != 1)
{
$go = $this->url."&screen=1";
return '< ';
}
}
// Use $p->getPrev() to return a link which will bring you to the last page.
function getPrev()
{
if ($this->page > 1)
{
$screen = $this->page - 1;
$go = $this->url."&screen=".$screen;
return '< ';
}
}
// Use $p->getLinks() to return links to all the pages.
function getLinks()
{
$link = "";
for ($links = 1;$links < ($this->pages + 1);$links++)
{
if ($links != $this->page)
{
$go = $this->url."&screen=".$links;
$link .= ' '.$links.' ';
}
else
{
$go = $this->url."&screen=".$links;
$link .= ' '.$links.' ';
}
}
return $link;
}
// Use $p->getNext() to return a link which will bring you to the next page.
function getNext()
{
if ($this->page < $this->pages)
{
$screen = $this->page + 1;
$go = $this->url."&screen=".$screen;
return '> ';
}
}
// Use $p->getLast() to return a link which will bring you to the last page.
function getLast()
{
if ($this->page != $this->pages)
{
$screen = $this->pages;
$go = $this->url."&screen=".$screen;
return '> ';
}
}
// Use $p->getViewFrom() to return the number you are viewing from.
function getViewFrom()
{
$from = "";
if ($from != 0)
{
$from = $this->start + 1;
return "$from ";
}
else
{
$from = $this->start;
return "$from ";
}
}
// Use $p->getViewTo() to return the number you are viewing to.
function getViewTo()
{
if (($this->start + $this->num) > $this->num_rows)
{
$to = $this->num_rows;
return $to;
}
else
{
$to = $this->start + $this->num;
return $to;
}
}
// Use $p->getViewing() to return the number of page you are currently viewing.
function getViewing()
{
return $this->page;
}
// Use $p->getViewingOf() to return the number of pages there are.
function getViewingOf()
{
return $this->pages;
}
// Use $p->getQuery() to return the query you want to call.
function getQuery()
{
return $this->query;
}
}
/*
Example:
$url = "?goto=page";
$query = "SELECT * FROM guestbook ORDER BY hg_id DESC";
$p = new dcPagination($url, $query, 50);
$query = $p->getQuery();
echo "On Page " . $p->getViewing() . " of " . $p->getViewingOf() . ", Viewing " . $p->getViewFrom() . " to " . $p->getViewTo() . "
";
echo $p->getFirst() . $p->getPrev() . $p->getLinks() . $p->getNext() . $p->getLast();
*/
?>