Yo de casualidad justo estaba probando hacer uno ya que nunca habia hecoh xD Te lo dejo para que lo veas, cambias las queries y el fetch segun tus necesidaes y te va a funionar, tiene hasta el CSS armado jeje saludos!
Si ves esto en el codigo: & #37 ; (sin espacios) reemplazalo por esto %
Código php:
Ver original<html>
<head>
<title>MySQL Test</title>
<style type="text/css">
<!--
body
{
font-family: 'Lucida Grande', 'Lucida Sans', 'Lucida Sans Unicode', 'Verdana', sans-serif;
font-size: 12px;
}
.page,
.page:active,
.page:link,
.page:visited
{
background: #F0F0F0;
border: 1px solid #CCC;
margin: 0 2px 0 2px;
padding: 4px 8px 4px 8px;
text-decoration: none;
color: #990000;
display: block;
float: left;
}
.page:hover
{
background: #FFF;
border: 1px solid #AAA;
}
.active
{
background: #FFF;
border: 1px solid #AAA;
margin-top: -2px;
padding: 6px 10px 6px 10px;
font-weight: bold;
color: #161616;
}
.page.below,
.page.above
{
margin-top: -1px;
padding: 5px 9px 5px 9px;
}
-->
</style>
</head>
<body>
<?php
// Get page
$page = $_GET['page'] ? $_GET['page'] : 1;
// Results per page
$rpp = 2;
// Get total news
$query = "SELECT * FROM news";
if ($total_news < 1) return print 'No results found. ';
if (($total_news % $rpp) != 0)
{
$last_page_results = $total_news % $rpp;
$total_pages = ($total_news - $last_page_results) / $rpp + 1;
}
else $total_pages = $total_news / $rpp;
$cp = 0;
for ($i = 1; $i <= $total_pages; $i++)
{
if ($last_page_results and $i == $total_pages)
{
$pages[$i] = $cp. ','. $last_page_results;
break;
}
$pages[$i] = $cp. ','. $rpp;
$cp+= $rpp;
}
if ($page > $total_pages) print 'No more pages after page '. $total_pages. '! ';
else
{
$_query = "SELECT id,title,content,date FROM news LIMIT ". $pages[$page];
{
print '<h4>' .$row['title']. ' (' .$row['date']. ')</h4>'."\r\n";
print '<p>' .$row['content']. '</p>'."\r\n";
}
if ($total_pages > 1) {
$back = ($page == 1) ? '' : ('<a href="?page=' .($page - 1). '" class="page">« Anterior</a>');
$first = ($page == 1 or $page == 2) ? '' : ('<a href="?page=1" title="Go to first page..." class="page">...</a>');
$below = ($page == 1) ? '' : ('<a href="?page=' .($page - 1). '" class="page below">' .($page - 1). '</a>');
$current = '<span class="page active">' .$page. '</span>';
$above = ($page == $total_pages) ? '' : ('<a href="?page=' .($page + 1). '" class="page above">' .($page + 1). '</a>');
$last = ($page == ($total_pages - 1) or $page == $total_pages) ? '' : ('<a href="?page=' .$total_pages. '" title="Go to last page..." class="page">...</a>');
$next = ($page == $total_pages) ? '' : ('<a href="?page=' .($page + 1). '" class="page">Siguiente »</a>');
print $back.$first.$below.$current.$above.$last.$next;
}
}
?>
</body>
</html>