I am creating a pagination using a text file as database instead of using mySQL. Already finished most of it, the only problem is the page numbering itself. How can I limit the maximum page numbering at the bottom part? And is there anyway to move to to the next set of pages after i press the last page number?
It's like this PREV 1 2 3 4 5 NEXT
<?php
// connect to txt database
$file="database.txt";
$con = file_get_contents($file);
// define how many results you want per page
$results_per_page = 5;
// find out the number of results stored in database
$linecount = 0;
$handle = fopen($file, "r");
while(!feof($handle)){
$line = fgets($handle);
$linecount++;
}
fclose($handle);
$number_of_results = $linecount;
// determine number of total pages available
$number_of_pages = ceil($number_of_results/$results_per_page);
// determine which page number visitor is currently on
if (!isset($_GET['page'])) {
$page = 1;
} else {
$page = $_GET['page'];
}
// display the links to the pages
for ($page=1;$page<=5;$page++) {
echo '<a href="index.php?page=' . $page . '">' . $page . '</a> ';
}
?>