I suppose you want to provide pagination using PHP. I created a guestbook with pagination for one of my pages. Basically i have all my entries in a MySQL database and using php code i achieve pagination. Maybe if you do not want to use a database, you can modify the algorithmus a little bit to work with text files.
Here is my code:
CODE
<?php
$sql_db = "Db_Name";
$sql_user = "Db_User";
$sql_pass = "Db_Passwd";
$sql_table = "Db_Table";
if(isset($pos)==0)
$pos=0; // start position for the page indexer
$count=3; // number of displayed items per page
mysql_connect("localhost", $sql_user, $sql_pass);
mysql_select_db($sql_db);
$result = mysql_query("select MAX(id) from ".$sql_table.";");
$data = mysql_fetch_assoc($result);
$size = $data['MAX(id)'];
$result = mysql_query("SELECT * FROM ".$sql_table." where id>".$pos.";");
if($result)
{
$i=0;
while(($data = mysql_fetch_assoc($result)) && ($i < $count))
{
// Here you should add text
$i++;
}
}
mysql_close();
print "<div>Pages:";
for($j=0; $j<$size; $j++)
if(!($j % $count))
print "<a href=\"book.php?pos=".$j."\">".(($j/$count)+1)."</a>\n";
print "Total number of entries: ".$size."\n";
if ($pos > 0)
print "<a href=\"book.php?pos=".($pos-$count)."\">Back</a>\n";
if($size > $pos+$count)
print "<a href=\"book.php?pos=".($pos+$count)."\">Next</a>\n";
?>
Let me know if i can help you in oder way.
Reply