Hello,
I haven't tested this, but it will get you started. We'll call your text file products.txt in this example. Be sure to add some error handling to this.
You have:
Product one | Desc one
Product two | Desc two
Product three | Desc three
Product four | Desc four
Product five | Desc five
Product six | Desc six
You want these paging links:
Page [1] [2]
//set the per page product limit
$products_per_page = 5;
//read the products text file into an array
$products = file("/root/path/products.txt");
//figure out how many products you have
$total_products = count($products);
//figure out how many pages you'll have
$total_pages = ceil($total_products/$products_per_page);
//$page must have at least a value of 1
if (!$page) {
$total_pages = 1;
} //endif
//make previous $page link if page > 1
if ($page != 1) {
$links = "<a href=\"$PHP_SELF?page=" . ($page - 1) . "\">[«]</a> ";
} //endif
if ($total_pages > 1) {
for ($i = 1; $i <= $total_pages; $i++) {
if($page == $i) {
$links .= "<font color=#000000> [$i]</font> ";
} else{
$links .= "[<a href=\"$PHP_SELF?page=$i\">$i</a>] ";
} //endif
} //endfor
} //endif
//make next page link if $total_pages > 1
if ($page != $total_pages) {
$links .= "<a href=\"$PHP_SELF?page=" . ($page + 1) . "\">[»]</a> ";
} //endif