breaking info from database into multiple pages
So I'm pulling information from a database. One of the fields, the interview field is rather long on some entries, so I want to break it down into multiple pages. It was suggested to me that I enter in [pagebreak] in the database field where I want the article to break at, so that I can ensure that it doesn't break mid sentence. This code is broken into 3 parts as I'm showing below. It's not currently working, it's breaking on this line:
function page_url(page) {
with the error: Parse error: syntax error, unexpected T_STRING, expecting ')'
In addition to that can you guys let me know if this set up looks good? Thanks! :)
PHP Code:
<?php
$page_break = "[pagebreak]";
// Default is page 1
$page = 1;
// Set the page we're currently on
if(isset($_GET["page"])) {
$page = $_GET["page"];
}
// Get our article body out of the database
$article_body = "This is page 1 of my article. [pagebreak] This is where page 2 of my article is.";
// Split our article into pages
$article_pages = str_split($article_body, $page_break);
?>
PHP Code:
<?php
// Display our page
print($article_pages[$page - 1]);
?>
<?php
function page_url(page) {
return "tvinterview.php?id=".$_GET["id"]."&page=".page;
}
$previous_link = "";
$next_link = "";
if($page > 1) {
previous_page = $page - 1;
$previous_link = page_url(previous_page);
}
if($page < count($article_pages)) {
next_page = $page + 1;
$next_link = page_url(next_page);
}
?>
PHP Code:
<ul class="page-navigation">
<!-- Previous Link -->
<?php if($previous_link == "") { ?>
<li>Previous</li>
<?php } else { ?>
<li><a href="<?php print($previous_link); ?>">Previous</a></li>
<?php } ?>
<!-- Numbered Links -->
<?php foreach($article_pages as $index => $page_body) { ?>
<?php if($page == $index + 1) ?>
<li><?php print($index + 1) ?></li>
<?php } else { ?>
<li><a href="<?php print(page_url($index + 1)); ?>"><?php print($index + 1); ?></a></li>
<?php } ?>
<?php } ?>
<!-- Next Link -->
<?php if($next_link == "") { ?>
<li>Next</li>
<?php } else { ?>
<li><a href="<?php print($next_link); ?>">Next</a></li>
<?php } ?>
</ul>