breaking up data from a db and presenting it on multiple pages.
My web site simply has a handfull of articles residing in a database (via mySQL). The user can simply view each one, but some of them are very long and I'd like to break them up. So, I have added an html tag (<pagebreak />) to each article in the database. My script pulls the article from my database, breaks up the article into multiple pages and then only displays one at a time.
I am attemping to lower the number of hits to the database. So, I am attempting to pull the entire article at once, then have the php script break it up. Below is what I currently have, but it's hitting the database for each page.
It seems like once I grab the article, I need to pass all of the variables for each page. However, I don't see a way to accomplish this.
Any thoughts?
<?php
function CreateArticleText() {
//global variables
global $db;
// pull articleBody from db and assign to $articleHash
$articleHash = BodyArticleRetrieve($db);
$page = explode("<pagebreak />", $articleHash[articleStory]);
return $page;
} // END Function CreateArticleText
if (!$page) { // if $page doesn't exist create it
$page = CreateArticleText();
$articleHash = BodyArticleRetrieve($db);
// print message to see if I'm hitting the database
print "<b>hitting the db</b><br><br>\n";
} else {
// print message to see if I'm not hitting the database
print "<b>not hitting the db</b><br><br>\n";
} // END IF
?>
<body>
<?php
// output page of article
print $page[$pageNumber] . "<br>\n";
// create navigation for all pages of article
for ($i = 0; $i < sizeof($page); $i++) {
if ( $i == $pageNumber ) {
$articleNav .= "Page " . $i . "<br>\n";
} else {
$articleNav .= "<a href=\"explode.php?pageNumber=" . $i . "\">Page " . $i . "</a><br>\n";
} // END IF
} // END FOR
// output navigation
print $articleNav;
?>
</body>