Hi,
I have looked at the class example - but could not understand how to apply it,
so I am adapting this code to my little application.
I like it because it isasy to follow and understand - but there are a couple of points
that I don't know about - and I hope that someone can put me right.
Here is the complete code:
First off , I guess that this is named view.php
Because it is called with an <a href from within ?
<?php
$limit = 20 // the number of rows per page
$query_count = "SELECT * FROM homes WHERE (topicid='$topicid') ORDER BY timestamp";
$result_count = mysql_query($query_count);
$totalrows = mysql_num_rows($result_count);
$PHP_SELF = $_SERVER['PHP_SELF']; // I DON'T UNDERSTAND THIS LINE ! WHY IS IT HERE
if(empty($page))
{
$page = 1;
}
$limitvalue = $page $limit - ($limit);
$query = "SELECT FROM posts,users WHERE (topicid='$topicid') AND username=name ORDER BY timestamp LIMIT $limitvalue, $limit";
$result = mysql_query($query) or die("Error: " . mysql_error());
if(mysql_num_rows($result) == 0)
{
echo("<center><b>Empty Post</b></center>");
}
while($row = mysql_fetch_array($result))
{
/////////////////
//posts here
/////////////////
if($page != 1)
{
$pageprev = $page - 1;
echo("<font size=1>Pages: </font>");
}
else
{
echo("<font size=1>Pages: </font>");
}
$numofpages = $totalrows / $limit;
for($i = 1; $i <= $numofpages; $i++)
{
if($i == $page)
{
echo("<font size=1>".$i."</font> ");
}
else
{
echo("<font size=1><a href='view.php?topicid=$topicid&page=$i'>$i</font></a> ");
// THIS BIT I ALSO DON'T KNOW ABOUT
// - MAYBE IT IS CALLING A DIFFERENT PROGRAM NOT THIS ONE? BECAUSE
// THERE IS NO $_GET AT THE BEGINNING OF THIS PROG ?
//
// WHAT IS THE &page DOING IN THIS BIT ?topicid=$topicid&page=$i
}
}
$last_page=ceil ($totalrows/$limit); // IS CEIL A BUILT-IN FUNCTION ?
if(($totalrows % $limit) != 0)
{
if($i == $page)
{
echo("<font size=1>" . $i . "</font> ");
}
else
{
echo("<a href='view.php?topicID=$topicID&page=$i'><font size=1>$i</font></a> ");
echo " ";
echo "<font size=1><a href=view.php?topicid=$topicid&page=$last_page#last>Last Page</a></font>";
}
}
if(($totalrows - ($limit * $page)) > 0)
{
$pagenext = $page + 1;
echo("<a href='$PHP_SELF?topicid=$topicid&page=$pagenext'><font size=1>>></font></a> ");
// I DON'T FOLLOW THIS BIT - WHAT DOES IT DO ?
}
else
{
echo("");
}
?>
thanks very much for any advice and what would you do to improve it ?
David.