Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

PHP Pagination (Adjacent)

$
0
0

Hello, I have manually created a simple pagination function, but unfortunately, I am having trouble when it comes to limit the number of pages shown... 

At the present, If there are 10 pages, I show all the pages, but my goal was to only show 5 pages... 

Example:

If I am on page 1 I only see:
[1] 2 3 4 5

 

If I am on two:

 

[2] 3 4 5 6

 

If I am on three: 

 

[3] 4 5 6 7

 

What should I do? this is my current cycle:

 

if($number_pages > $num_pages_list /*5 in this case*/)
{
 
for($i=1; $i <= $number_pages; $i++)
{
if($i == $_GET['page'])
{
echo '<a href="'.$page.'?page='.$i.'&i='.($results_page*$i-$results_page).'"><b>'.$i.'</b></a>';
}else{
echo '<a href="'.$page.'?page='.$i.'&i='.($results_page*$i-$results_page).'">'.$i.'</a>';
}
}

 

}
 
In this example I still show every page...

Viewing all articles
Browse latest Browse all 13200

Trending Articles