I use the following code to display and paginate the log entries from a flatfile DB (one line per record with 5 fields delimited by | pipe symbols, such
as "name|address|city|state|zip"). I presently can navigate the pages with "Next Page" or "Previous Page" but would like to also display the number of pages available with links to each page. It would also help if I can count and display the total number of records (lines) in the DB.
I am fairly new to PHP and would appreciate any assistance you can provide. Thank you so much.
<?php
$data = file("passed.txt");
$perpage = 20;
if(isset($_GET['start'])) $start = $_GET['start']; else $start = 0;
$numposts = count($data);
$data = array_slice($data, $start, $perpage);
foreach($data as $k => $v)
{
echo $data[$k].''."\n";
}
if($start > 0)
{
$text .= '<a href="tracking_log.php?start='.($start - $perpage).'">< Previous Page </a>';
}
if($start > 0 && $numposts > $perpage && $start < $numposts - $perpage)
{
$text .= ' | ';
}
if($numposts > $perpage && $start < $numposts - $perpage)
{
$text .= '<a href="tracking_log.php?start='.($start + $perpage).'">Next Page ></a>';
}
echo $text;
?>