Fredrik Tornell
Fredrik Tornell

Reputation: 23

Simple pager php previous and next

I have read a bunch of tools and I copied some code but the code is half a mile! :) I was wondering if its not possible to make a small one like this (you'll get my point) Im just after a small pager with previous and next links to display the next page of results...

<?php

//pagination

$pagelimit = 5

$result = mysql_query("SELECT * FROM blog ORDER BY id DESC LIMIT $pagelimit")
or die(mysql_error());

while($row = mysql_fetch_array( $result )) {

echo $row['title'];

}

echo "<a href='index.php?page=" . $row[$id - $pagelimit] . "'> Previous</a></li>";
echo "<a href='index.php?page=" . $row[$id + $pagelimit] . "'> Next</a></li>";

?>

or something similar...that works! :)

Upvotes: 0

Views: 506

Answers (1)

Kloar
Kloar

Reputation: 1160

Here's a suitable tutorial: Paging Using PHP

In short, you should use $_GET['page'] to add an offset in your mysql query, which will look something like this (you'll have to adjust it to make it fit your implementation, but it's the basic syntax)

SELECT * FROM blog ORDER BY id DESC LIMIT $offset, $pagelimit

Upvotes: 3

Related Questions