Break up flat file contents 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
katlis
Forum Newbie
Posts: 10
Joined: Mon Nov 05, 2007 12:42 pm

Break up flat file contents into pages?

Post by katlis »

Hi there, I have a simple script that that writes to a flat txt database, with entry#|name|email ... like this:

3|bob|bob@blah.com
2|john|john@domain.com
1|kathy|kath@whatever.com

If I have a txt file with 50 lines, how can I display the contents into pages of 10 entries? Like: "results 1-10 of 50, next page"... With the pages using a query like display.php?page=2

Any help is greatly appreciated.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

For the number of lines you are talking about, I would just read the whole file into an array and just show the range for the current page (start=(page-1)*page_size). Check the file system functions for reading the file into an array.
(#10850)
katlis
Forum Newbie
Posts: 10
Joined: Mon Nov 05, 2007 12:42 pm

Post by katlis »

I know how to get the file in an array, it's the displaying the range part I dont get.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

arborint told you: (start=(page-1)*page_size)

Or if you prefer:

Code: Select all

$start = $records_per_page * ($page_num - 1);
Post Reply