verbazon Posted December 14, 2007 Share Posted December 14, 2007 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: http://biorust.com/index.php?page=tutorial_detail&tutid=103" 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 /> <span style="margin-left:5px;" />Author: ' . $row['author'] . '<br /> <span style="margin-left:5px;" />Date: ' . $row['date'] . ' <p>' . nl2br($row['content']) . '</p>'; } $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 ?> Quote Link to comment Share on other sites More sharing options...
VirusDoctor Posted December 14, 2007 Share Posted December 14, 2007 Hi, from what I can see, you need to replace <a href='http://mysite.com/index.php?start=".$previous."'>Previous Page[/url] - <a href='http://mysite.com/index.php?start=".$next."'>Next Page[/url] with <a href='http://mysite.com/index.php?start=".$previous."'>Previous Page</a> - <a href='http://mysite.com/index.php?start=".$next."'>Next Page</a> Quote Link to comment Share on other sites More sharing options...
slarkler Posted December 14, 2007 Share Posted December 14, 2007 Hey, VirusDoctor - that was just added by the forum here. I tried to post some code without using the 'code' thing, and it changed the link closing tags to those 'url' things. Quote Link to comment Share on other sites More sharing options...
verbazon Posted December 14, 2007 Author Share Posted December 14, 2007 Hi please ignore the block at the end of the <a> tags.. it should be </a> Can someone please help me with this? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.