Hi all I've been teaching myself pagination, though I have a general question about using a link to view the next set of results.
I am able to display the data in a table using the code below. With my second code example I can get the links displayed e.g. 1,2,3,4 Next. And the numbers change depending on how many records should be displayed. Though my problem arrives when I press the link to view the next page of results. The page reloads but the same set of results is displayed. Any assistance or help would be greatly appreciated.
The code below is used to count the record and a set a variable for the amount of records displayed on screen at any one time.
<?
$per_page = 4;
$start = 0;
$result = mysql_query("select * from blogentry WHERE approve = 'Y' order by timeleft ASC");
//count records
$record_count = mysql_num_rows($result);
//count max pages
$max_pages = $record_count / $per_page; //may come out as decimal
if (!$start)
$start = 0;
$get = mysql_query("select * from blogentry WHERE approve = 'Y' order by timeleft ASC LIMIT $start, $per_page");
while ($row = mysql_fetch_assoc($get))
{
$usn1 = $row['username'];
$tml1 = $row['timeleft'];
$bge1 = $row['blogentry'];
$irm1 = $row['ResponceMess'];
echo "<table>"
Table code intentionally left out
echo "</table>"
The code below is used to display the pagination though when the link is pressed the same results is displayed:
//setup prev and next variables
$prev = $start - $per_page;
$next = $start + $per_page;
if(!($start<=0))
echo "<a href'messages.php?start=$prev'>Prev</a>";
//set variable for first page
$i=1;
//show page numbers
for ($x = 0; $x < $record_count; $x = $x + $per_page)
{
if ($start != $x)
echo " <a href='messages.php?start=$x'>$i</a> ";
else
echo " <a href='messages.php?start=$x'><b>$i</b></a> ";
$i++;
}
//show next button
if (!($start >= $record_count - $per_page))
echo " <a href='messages.php?start=$next'>Next</a>";
?>