Hi, i'm trying to get a small php pagination script to work with my news system. I followed a tutorial from a website callled biorust here

The only thing that works is it's correctly limiting my news posts to display 3 at once. But the previous and next page links don't work. They show up as
http://mysite.com/index.php?start=3 (Previous Page)
http://mysite.com/index.php?start=-3 (Next Page)

and they don't do anything when clicked on. How can I make it so they display a new page with the next 3 news posts? Here is the code:

<?php
if ( $_GET['number'] == NULL ){
$limit = 3;
} else {
$limit = $_GET['number'];
}

if ($_GET['page']==NULL){
$start = 0;
} else {
$start = $_GET['page'];
}

// the if above, states that if the variable in the URL named page has a value, $start will be set to it, otherwise by default it is set to 0, meaning that it will start at the beginning of the table by default.

if($_GET['page'] < 0){
header("Location: http://mysite.com/index.php?page=0&limit=".$limit);
}

// this if above checks that the start variable isn’t negative, because if it is, our script will screw up. If it finds that it is, it redirects to the default page where the start is 0.


$query = mysql_query("SELECT * FROM `mytable` ORDER BY `id` DESC LIMIT ".$start.",".$limit.";") or die('MySQL Error: ' . mysql_error());
while($row = mysql_fetch_array($query))
{
	echo '<h2>' . $row['title'] . '</h2>
		<br />
		<b><span style="margin-left:5px;" />Author: </b>' . $row['author'] . '<br />
		<b><span style="margin-left:5px;" />Date: </b>' . $row['date'] . '
		<p>' . nl2br($row['content']) . '</p><hr />';
}

$previous = $start + $limit;
$next = $start - $limit;
echo "<div align='center'>
	<a href='http://mysite.com/index.php?start=".$previous."'>Previous Page</a> - 
	<a href='http://mysite.com/index.php?start=".$next."'>Next Page</a>
		</div><br />";

// the set of statements above displays the previous and next page links
?>

    can anyone please help me out with this? 🙁 thanks

      correct me if i'm wrong but i think you have previous and start back wards.

      shouldn't previous be $start - $limit and $next be $start + $limit?

        either way it's not working, i've lost hope

          Write a Reply...