Help Learning Classes
| From: | Ross Bateman | Date: | Tue, 15 Apr 2003 10:17:04 +0000 |
| Subject: | Help Learning Classes | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-143894@lists.php.net to get a copy of this message | ||
Hi
I am trying to get my head around classes. I have the following script that
when run as a function works great, but I can not get it to function as a
class.
I call it:
include($root_path . "include/oop_page_nav.php");
$topnav = &New page_navigation;
$topnav->page_navigation($PHP_SELF, $totalrows, $limit, $page);
This is the script but it generates a lot of errors.......and then seemes to
give me the nav that I was trying to get.
<?php
class page_navigation
{
var $link;
var $totalrows;
var $limit;
var $page;
function page_navigation($link, $totalrows, $limit, $page)
/* This is the constructo that will cause the function to
execute when the class is called */
{
if($page != 1)
/* If $page is not 1 then there will be a prev link in the nav panel
*/
{
$pageprev = ($page - 1);
echo "<a href=\"" . "$link" .
"?page=$pageprev\">prev</a> ";
}
else
{
echo "prev ";
}
/* Set up the page numbers */
$numofpages = $totalrows / $limit;
for($i = 1; $i <= $numofpages; $i++)
{
if($i == $page)
{
echo $i . " ";
}
else
{
echo "<a href=\"" . "$link" .
"?page=$i\">$i</a> ";
}
}
/* Get remainder of pages */
if(($totalrows % $limit) != 0)
{
if($i == $page)
{
echo $i . " ";
}
else
{
echo "<a href=\"" . "$link" .
"?page=$i\">$i</a> ";
}
}
/* Show next link
if we are on the last page number, there will be no next link */
if(($totalrows - ($limit * $page)) > 0)
{
$pagenext = ($page + 1);
echo "<a href=\"" . "$link" .
"?page=$pagenext\">next</a>";
}
else
{
echo " next";
}
/* end function */
}
}
?>
Thanks,
Ross