I have done the tutorial, and I have 'kind' of got my head around it, but I am only getting non-link PREV and NEXT.
I echoed $page, marked in the code, but only got the answer 1.
If anyone knows a lot about pagination, what am I missing here? Thanks in advance for any help.
// get the name of the currently required Category from the database matching the pressed link in top2.php
$tresult = mysql_query("select subjectlist.subject_name from subjectlist where subjectlist.subject_name='$topic' or subjectlist.subject_name='lifestyle'") or die(mysql_error());
$trows = mysql_num_rows($tresult);
for($h = 0; $h < $trows; $h++)
{
$tdata = mysql_fetch_row($tresult);
echo "<h3>$tdata[0]</h3><br>\n"; // print topics to screen ***************
/// set the size of the pages
$limit = 5;
// if page variable is empty we are on page 1
if(empty($page))
{
$page = 1;
}
// Ex: (2 * 5) - 5 = 5 <- data starts at 5
$limitvalue = $page * $limit - ($limit);
// retrieve the topic names from subjectlist table
$result = mysql_query("select TBTree.NodeId, TBTree.NodeName, TBArticle.NodeId, TBTree.CategoryName, TBArticle.ArticleSubject, TBArticle.ArticleDateTime, TBArticle.ArticleId from TBArticle, TBTree where TBTree.CategoryName='$topic' and TBArticle.NodeId=TBTree.NodeId limit $limitvalue, $limit") or die(mysql_error()); // order by TBArticle.ArticleSubject asc limit 5 //
$rows = mysql_num_rows($result);
// if there are no results returned then comment
if(mysql_num_rows($result) === 0)
{
echo "Nothing to display";
}
// put the contents of $rows into variables for use
for($k = 0; $k < $rows; $k++)
{
while($rows = mysql_fetch_object($result))
{
$temp_data5 = ($rows -> NodeName);
$temp_data4 = ($rows -> NodeId);
$temp_data3 = ($rows -> ArticleId);
$temp_data2 = ($rows -> CategoryName);
$temp_data1 = ($rows -> ArticleDateTime);
$temp_data = ($rows -> ArticleSubject);
echo "<table>\n";
echo "<tr><td class=\"left\"><a href=\"index9.php?temp_data5=$temp_data5&temp_data4=$temp_data4&temp_data3=$temp_data3&temp_data2=$temp_data2&temp_data1=$temp_data1&temp_data=$temp_data\" target=\"_top\">$temp_data</a></td><td class=\"right\">$temp_data1</td><tr>\n";
echo "</table>\n";
}
//echo "page is: $page"; <<---- PAGE IS ALWAYS 1 HERE: ---> NOT GOOD
if($page != 1)
{
$pageprev = $page--; // subtract 1 from page
echo "<a href=\"$display_categories.php?page=$pageprev\">PREV".$limit."</a> ";
}
else
{
echo "PREV".$limit."</a> ";
}
// divide the total amount of returned articles by $limit
$numofpages = $rows / $limit;
// add 1 to $i until $i > $numofpages
for($i = 1; $i <= $numofpages; $i++)
{
// this if will not make current page number a link but all other pages will be links
if($i == $page)
{
echo "$i ";
}
else
{
echo "<a href=\"$display_categories.php?page=$i\">$i</a> ";
}
}
// this returns the remainder but is basically as above
if(($rows % $limit) != 0)
{
if($i = $page)
{
echo "$i ";
}
else
{
echo "<a href=\"$display_categories.php?page=$i\">$i</a> ";
}
}
// if there are more rows remaining in front of the current one
if(($rows - ($limit * $page)) > 0)
{
$pagenext = $page++;
echo "<a href=\"$display_categories.php?page=$pagenext\">NEXT".$limit."</a> ";
}
else
{
echo "NEXT".$limit;
}
mysql_free_result($result);
}
}