I found this somewhere a while ago but i can't remember where (attahced)
You just need to choose one of the functions so i chose the one in my example
Here is the CSS for it
.page_numbers {
width: 600px;
padding: 5px 0px;
float:left;
clear:left;
margin:0 auto;
}
.page_numbers ul {
margin: 0 auto;
list-style-type: none;
padding: 0px;
text-align: center;
}
.page_numbers li {
display: inline;
float: left;
margin:1px;
background: #a7a7a7;
width:25px;
}
.page_numbers li.current{
width:50px;
}
.page_numbers li a {
background: #fff;
border: 1px solid #a7a7a7;
padding: 1px;
text-decoration: none;
color: #000;
font:bold 8px verdana,sans-serif;
display:block;
}
.page_numbers a.current, .page_numbers li a:hover {
background: #a7a7a7;
color: #fff;
}
and an example of how to use it (i couldn't be bothered to edit it....too many beers 🙂 )
<h2>General Articles</h2><hr />
<div>
<?php
include "includes/connection.php";
$webpage = basename(articles);
function pagination_five($total_pages,$page){
global $webpage;
$max_links = 10;
$h=1;
if($page>$max_links){
$h=(($h+$page)-$max_links);
}
if($page>=1){
$max_links = $max_links+($page-1);
}
if($max_links>$total_pages){
$max_links=$total_pages+1;
}
echo '<div class="page_numbers">
<ul>';
if($page>"1"){
echo '<li class="current"><a href="/'.$webpage.'/1">First</a></li>
<li class="current"><a href="/'.$webpage.'/'.($page-1).'">Prev</a></li>
';
}
if($total_pages!=1){
for ($i=$h;$i<$max_links;$i++){
if($i==$page){
echo '<li><a class="current">'.$i.'</a></li>';
}
else{
echo '<li><a href="/'.$webpage.'/'.$i.'">'.$i.'</a> </li>';
}
}
}
if(($page >="1")&&($page!=$total_pages)){
echo '<li class="current"><a href="/'.$webpage.'/'.($page+1).'">Next</a></li>
<li class="current"><a href="/'.$webpage.'/'.$total_pages.'">Last</a></li>
';
}
echo '</ul>
</div>
';
}
$result = mysql_query("Select count(*) from articles WHERE archived='n'")
or die (mysql_error());
$numrows = mysql_fetch_row($result);
if(isset($_GET['pagenum'])?$page = $_GET['pagenum']:$page = 1);
$entries_per_page = 1;
$total_pages = ceil($numrows[0]/$entries_per_page);
$offset = (($page * $entries_per_page) - $entries_per_page);
//after we have $total_pages and $page, we can include the
//pagination style wherever we want on the page.
//so far there is no output from the script, so we could have
//pagination before or after the pages results
//before the results
$result = mysql_query("SELECT id,title,content, DATE_FORMAT(time, '%W %D %M %Y') as date, photo FROM articles WHERE archived='n' ORDER BY id DESC LIMIT
$offset,$entries_per_page");
if(!$result) die(mysql_error());
$err = mysql_num_rows($result);
if($err == 0) die("No matches met your criteria.");
while($row=mysql_fetch_array($result)){
$title = htmlentities(strtoupper($row['title']));
$content = htmlentities($row['content']);
if (!$row['photo']){
echo "<div id='right'><h3>".$title."</h3><p style='text-align:left'><i>Date added: ".$row['date']."</i></p><p>".nl2br($content)."</p><br /></div>\n";
} else {
echo "<div id='right'><h3>".$title."</h3><p style='text-align:left'><i>Date added: ".$row['date']."</i></p><p><img src='/images/large/".$row['photo']."' alt='".$row['alternate']."' class='right' />".nl2br($content)."</p><br /></div>\n";
}
}
//or after the results
pagination_five($total_pages,$page);
?>
</div>