Forum Moderators: coopster

Message Too Old, No Replies

pagination help

         

lenny

2:50 am on Dec 22, 2009 (gmt 0)

10+ Year Member



Hello Everyone, hope i can get some help here as I cant seem to contact the guy who coded my site for me.

Looking for some help on pagination. I listed to code that im using on my site below, problem is it shows previous - all news pages 200 of them - then next . What i want to get it to do is just show a range of them no matter what page your on. So for ex if your on page 35 of the news articles it shows 30-31-32-33-34-35-36-37-38-39-40 instead of all 200 of them

You can see what i mean by this page in my site <snip>

heres is the pagination code that is currently being used, think i have to change something in the middle of it , any help appreciated.

<?
if($page > 1){
$prev = ($page - 1);
echo "<a href=news.php?page=$prev class='yellow_link'>Previous</a> ";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "$i ";
} else {
echo "<a href=news.php?page=$i class='yellow_link'>$i</a> ";
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
echo "<a href=news.php?page=$next class='yellow_link'>Next</a>";
}
echo "</center>";
?>

[edited by: eelixduppy at 6:51 am (utc) on Dec. 22, 2009]
[edit reason] no personal URLs, please [/edit]

ALKateb

12:26 pm on Dec 22, 2009 (gmt 0)

10+ Year Member



<?
if($page > 1){
$prev = ($page - 1);
echo "<a href=news.php?page=$prev class='yellow_link'>Previous</a> ";
}
if($page <= 5){
$start_page = 1;
$end_page = 10;
}else{
$start_page = $page - 5;
$end_page = $page + 5;
}
for($i = $start_page; $i <= $total_pages and $i < $end_page; $i++){
if(($page) == $i){
echo "$i ";
} else {
echo "<a href=news.php?page=$i class='yellow_link'>$i</a> ";
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
echo "<a href=news.php?page=$next class='yellow_link'>Next</a>";
}
echo "</center>";
?>