Page 1 of 1

Navigation Bar for Query

Posted: Sun Sep 25, 2011 6:51 am
by mareksl
Hey!
I need some help creating a "Previous 1 2 3 4 ... Next" type navigation bar for my website.
I have found some online, but have had trouble using them.
Here is my query:

Code: Select all

<?php }
$con = mysql_connect("***","***","***");
if (!$con){die('Could not connect: ' . mysql_error());}
mysql_select_db("***", $con);

$result = mysql_query("SELECT * FROM updates ORDER BY date DESC LIMIT 0, 10");
while($row = mysql_fetch_array($result))
{?>
<div id="comment">
<?php echo $row['date'] ?><br />
<b><?php echo $row['title'] ?></b><?php if ($user->data['user_rank'] == 1 || $user->data['user_rank'] == 2) {?>
<a href="news.php?type=delete&newsid=<?php echo $row['ID'];?>"> | Remove</a>
<?php } ?><br />
<?php echo $row['entry'] ?>
</div>
<?php }
mysql_close($con);
?>
Can someone please help me, post some working scripts, useful links, show me the way or just write the code for me?
What I want is to display 10 results, and under them a navigation bar to navigate through the results.
Thanks in advance! :)

Re: Navigation Bar for Query

Posted: Sun Sep 25, 2011 7:37 am
by Eric!
What you're looking for is called pagination; a word that describes how to make pages out of a long list of results. For something quick and cool, try Pear's pager class. Here's a tutorial http://www.codediesel.com/php/simple-pagination-in-php/

If you want a procedural method that has no library dependencies: http://www.phpfreaks.com/tutorial/basic-pagination

Or you might like sitepoints Paginated class http://www.sitepoint.com/perfect-php-pagination/ that you can download.

Re: Navigation Bar for Query

Posted: Sun Oct 02, 2011 9:06 am
by mareksl
Thanks a lot! I'll look into it!
I like the part in the second link:
In fact, in my experience over the years of helping out on the forums, peoples' hardest problem about pagination is figuring out what it's called in the first place!
Fits my situation! :)