Re: counting pages...
| From: | John W. Holmes | Date: | Tue, 27 Apr 2004 12:49:53 +0000 |
| Subject: | Re: counting pages... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-184753@lists.php.net to get a copy of this message | ||
From: <Tristan.Pretty@risk.sungard.com>
> I want to convert my page counter to display just a limited No of page
> options...
> Currently, after my database request, I'm getting 1000's of pages...
> I want to do something like:
>
> < < Previous -21 22 23 24 25 26+ Next > >
>
> Anyhoo, here's my current code...
> =================================
>
> if($page > 1){
> $prev = ($page - 1);
> $start_pick = "<a
> href=\"".$_SERVER['PHP_SELF']."?page=$prev\">< <
> Previous</a> ";
> } else {
> $start_pick = "< < Previous ";
> }
>
> for($i = 1; $i <= $total_pages; $i++){
So, you know you're on $page and you want to go from $page-10 to $page+10,
right?
$startpage = max(1,$page-10);
$endpage = min($page+10,$total_pages);
for($i=$startpage; $i <= $endpage; $i++) {
and then carry on with the rest of your code.
---John Holmes...