Navigation Bar for Query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mareksl
Forum Newbie
Posts: 18
Joined: Tue Mar 08, 2011 12:24 pm
Location: Poland

Navigation Bar for Query

Post 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! :)
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Navigation Bar for Query

Post 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.
User avatar
mareksl
Forum Newbie
Posts: 18
Joined: Tue Mar 08, 2011 12:24 pm
Location: Poland

Re: Navigation Bar for Query

Post 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! :)
Post Reply