Page 1 of 1

Break up flat file contents into pages?

Posted: Mon Nov 05, 2007 1:09 pm
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.

Posted: Mon Nov 05, 2007 2:03 pm
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.

Posted: Mon Nov 05, 2007 2:10 pm
by katlis
I know how to get the file in an array, it's the displaying the range part I dont get.

Posted: Mon Nov 05, 2007 2:54 pm
by Oren
arborint told you: (start=(page-1)*page_size)

Or if you prefer:

Code: Select all

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