|
Posted by Carl on 11/15/73 11:22
guitarromantic@gmail.com wrote:
> That's great Carl, you can see the progress from the same url above.
> Incidentally, you're correct with what method I was using.
>
> My only issue now is generating the values for the range of pages. IE,
> on the current article linked above, it displays:
>
> Total Pages: 3
>
> Current Page: 1
>
> I need to create a list like "Page: 1 | 2 | 3"
>
> How can I use this data to do that? I basically want it to display a
> link to any other existing pages, but not link the current page.
> Apologies if this is blindingly obvious, I'm new to php.
>
> Thanks again!
> Matt
>
Simple, just loop through the pages and appending a new link for each
page you have.
Something like:
/*
* start code. UNTESTED!
*/
$links = 'Page: ';
for ($x = 1; $x <= $pageCount; $x++){ // each page in $pageCount
if ($x == $_GET['page']){
$links .= $x; // current page, no link.
} else {
$links .= '<a href="foo.php?page=' . $x . '">';
$links .= $x . '</a>';
}
// add sep char
if ($x < $pageCount){
$links .= ' | ';
}
}
/*
* end code
*/
Now the string $links contains a link for each page represented by
$pageCount. Just echo the $link var.
You probably want to add some code to enforce a $MAX_LINKS option, so
that in the case of a very long article you don't end up printing a
whole screenful of links.
Carl.
[Back to original message]
|