By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,346 Members | 2,318 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,346 IT Pros & Developers. It's quick & easy.

Splitting an article into multiple pages.

P: n/a
Hey everyone.

Following advice found online, I figured out a basic way of splitting a
long article into several pages, by exploding out from a
<!--pagebreak--> code in my $content field.

http://www.scenepointblank.com/matt/...hp?id=1&page=1

Sample above. The next/previous links were built with simple values:

$pagenext = ($_GET['page']) + 1;
$pageprev = ($_GET['page']) - 1;

This is pretty basic level stuff (and knowing my luck, probably
horribly insecure too..), so what I really need is for the system to
know how many "pages" there are (or how many sections split by
<!--pagebreak--> tags), and then I can work with this value, and print
a list like "Page 1 | Page 2 | Page 3" rather than just basic
previous/next links. How can I do this?

Jul 26 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
gu************@gmail.com wrote:
Hey everyone.

Following advice found online, I figured out a basic way of splitting a
long article into several pages, by exploding out from a
<!--pagebreak--> code in my $content field.

http://www.scenepointblank.com/matt/...hp?id=1&page=1

Sample above. The next/previous links were built with simple values:

$pagenext = ($_GET['page']) + 1;
$pageprev = ($_GET['page']) - 1;

This is pretty basic level stuff (and knowing my luck, probably
horribly insecure too..), so what I really need is for the system to
know how many "pages" there are (or how many sections split by
<!--pagebreak--> tags), and then I can work with this value, and print
a list like "Page 1 | Page 2 | Page 3" rather than just basic
previous/next links. How can I do this?


I'm not 100% sure I understand your question; are you separating your
'pages' by entering the text "<!--pagebreak-->" in your content, and
then using the explode() method to break up the pages?

If that is correct, then given:

$allPages = explode('<!--pagebreak-->', $content);
$pageCount = count($allPages); // total # of pages found
$currentContent = $allPages[$_GET['page']]; // current page content

Hope that helps,
Carl.
Jul 26 '05 #2

P: n/a
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

Jul 26 '05 #3

P: n/a
gu************@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.
Jul 26 '05 #4

P: n/a
Thanks again. I had to hack this slightly since page 1 is called as
page=0 in the code, but I have it working fine now. As for the
$MAX_LINKS option, it won't be neccessary, we tend to split things into
a maximum of 4 pages or so, I couldn't see it ever being more than this.

Jul 26 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.