Page 1 of 1

Breaking records into pages

Posted: Fri Oct 16, 2009 4:09 am
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... :)

Re: Breaking records into pages

Posted: Fri Oct 16, 2009 4:19 am
by litarena
What does only 10 news mean?

Re: Breaking records into pages

Posted: Fri Oct 16, 2009 7:37 am
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

Re: Breaking records into pages

Posted: Fri Oct 16, 2009 7:56 am
by krystof78
Thank you for your answer but I actually found what I needed on another website with this tutorial:
LINK

Thanks anyway.

Cheers.

Re: Breaking records into pages

Posted: Fri Oct 16, 2009 7:58 am
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

Re: Breaking records into pages

Posted: Fri Oct 16, 2009 8:08 am
by krystof78
Thanks for your answer too! :)