Jump to content

Spliting data into pages


dcole07

Recommended Posts

  • 2 years later...
I imagine the text file is:

data1.1, data1.2, data1.3...
data2.1, data2.2, data2.3...
....
data11.1, data11.2, data11.3...
data12.1, data12.2, data12.3...

Why not use a database then? It would be way more efficient. Anyway, as suggested above, use explode to have the groups in an array. Seperate each ten group with a word (like: "--next group--") or two brakes to explode them easily. Then depending on the page, show the info. Smth like this:

[code]
<?php
$handle = fopen('file.txt', 'r'); //open file as read only
$contents = fread($handle, filesize('file.txt')); //read the file
$data = explode('--next group--', $file); //explode the groups
if(isset($_GET['page']) and $_GET['page'] != count($data) + 1){ //the whole block: sets the key of the array depending on the page
     $dataKey = $_GET['page'] - 1;
} else{
     $dataKey = 0;
}
echo $data[$dataKey];
?>
[/code]

The idea of all that, is to get the page data and use it as the key of the array. So for page=1, u could show array[0] (as array keys start from 0) and so on.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.