AN, here's a very useful script...
PHP Code:
<?php
$max_results = 10;
// Database Connection
if(!isset($HTTP_GET_VARS['page']))
{
$page = 1;
}
else
{
$page = $HTTP_GET_VARS['page'];
}
$first_item = (($page * $max_results) - $max_results);
// Perform MySQL query on only the current page number's results
$sql = mysql_query("SELECT * FROM pages LIMIT $first_item, $max_results");
while($row = mysql_fetch_array($sql)){
echo $row['title']."<br />";
}
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM pages"),0);
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
// Build Page Number Hyperlinks
echo "<center>Select a Page<br />";
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<Previous</a> ";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "$i ";
} else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ";
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>></a>";
}
echo "</center>";
?>
I'm sure you can get a few ideas from there..
See my next post for a fixed (I hope) query...
Regards,
Patrick