Here is the script as I am using it now:
<?php
echo '<html><body>';
// Data from a flat file
$dataArray = file('text.dat');
// Get the current page
if (isset($_REQUEST['page'])) {
$currentPage = $_REQUEST['page'];
} else {
$currentPage = 'some default value';
}
// Pagination settings
$perPage = 3;
$numPages = ceil(count($dataArray) / $perPage);
if(!$currentPage || $currentPage > $numPages)
$currentPage = 0;
$start = $currentPage * $perPage;
$end = ($currentPage * $perPage) + $perPage;
// Extract ones we need
foreach($dataArray AS $key => $val)
{
if($key >= $start && $key < $end)
$pagedData[] = $dataArray[$key];
}
foreach($pagedData AS $item) {
$item = explode('||', $item);
echo '<a href="/'. $item[1] .'/index.php">'. $item[0] .'</a><br>';
}
if($currentPage > 0 && $currentPage < $numPages)
echo '<a href="?page=' . ($currentPage - 1) . '">« Previous page</a><br>';
if($numPages > $currentPage && ($currentPage + 1) < $numPages)
echo '<a href="?page=' . ($currentPage + 1) . '" class="right">Next page »</a><br>';
echo '</body></html>';
?>
And here is the contents of text.dat
Fun||http://site.com/page11.html
Games||http://site.com/page12.html
Toys||http://site.com/page13.html
Sports||http://site.com/page16.html
Fishing||http://site.com/page18.html
Pools||http://site.com/page41.html
Boats||http://site.com/page91.html
Here is my question. There are Seven lines in this array. How can I display the line number (I think it is $key) next to my displayed link? I should end up a list of links, each with it own number like:
LINE NUMBER - <a href="/'. $item[1] .'/index.php">'. $item[0] .'</a><br />
Thanks for any assistance…..
I’m assuming you want the line number from the file and not the line number of the output. If so, then change this:
to something like this: