Breaking records into pages

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
krystof78
Forum Newbie
Posts: 10
Joined: Fri Oct 16, 2009 4:08 am

Breaking records into pages

Post by krystof78 »

Hi guys,

I am struggling with some code for a couple of days and can't figure out what to do. I have to admit that I am pretty new at php.

Here is my issue. I have a table in my database recording all the news of my website. Pretty simple table with these fields:
  • [li]id[/li]
    [li]menu_name[/li]
    [li]visible[/li]
    [li]content[/li]
So pretty simple to display all the news on my website. But I guess I will have some trouble when I will have lots of news, showing a long page of news.

How can I display these news so that only 10 news appear on page 1 and just below, people can go to other pages?

Thanks in advance for your help guys... :)
litarena
Forum Newbie
Posts: 14
Joined: Tue Sep 01, 2009 3:39 am

Re: Breaking records into pages

Post by litarena »

What does only 10 news mean?
firdous_kind86
Forum Newbie
Posts: 8
Joined: Wed Oct 07, 2009 5:06 am

Re: Breaking records into pages

Post by firdous_kind86 »

while fetching records you will have to use a query to fetch the latest 10 records, you arrange them by datetime and fetch only latest 10 items

then you should place a condition that if total number of records in news table are greater than 10 then you should "echo" a link to a "next page" which will display the rest, a little planning will be required but not that difficult

Hope that it helps
krystof78
Forum Newbie
Posts: 10
Joined: Fri Oct 16, 2009 4:08 am

Re: Breaking records into pages

Post by krystof78 »

Thank you for your answer but I actually found what I needed on another website with this tutorial:
LINK

Thanks anyway.

Cheers.
synical21
Forum Contributor
Posts: 150
Joined: Tue Jul 28, 2009 8:44 am
Location: London UK

Re: Breaking records into pages

Post by synical21 »

mysql_query(SELECT * from `news` ORDER BY `date` DESC LIMIT 10) or die( mysql_error() );

thats an example of the query you could use, as for making it display over pages google "pagination php"

EDIT: you posted as i was typing :P
krystof78
Forum Newbie
Posts: 10
Joined: Fri Oct 16, 2009 4:08 am

Re: Breaking records into pages

Post by krystof78 »

Thanks for your answer too! :)
Post Reply