I understand how to break a series of records into pages, but how would I break ONE record into a series of pages?
It depends on the specifics of what your “record” is.
Put a bit more effort into describing what you want to do.
My table consists of two fields (ID, CONTENT). There is only one record and the CONTENT is just text of about 500 words. Instead of the user scrolling down to read the content, I’d like to keep it at a specific length, with page navigation (or links) to the next page.
I hope this was the description you were looking for.
Say your table is called my_contents, and you wanted to get the intros to the last 20 articles, you may do something like:
$sql = "select id, LEFT(content, 50) as intro from my_contents LIMIT 20" ;
that’d give you some text ( an intro, or teaser) and a key to get the full story:
foreach( $intros as $intro ){
echo '<li><a href="fullarticle.php?id='
. $intro['ID'] . '">'
. $intro['intro'] .'</a></li>';
}
Personally (and I think I’m not alone), I hate this I’d far rather scroll, but anyway …
You’ll need to think about how you split the content - by paragraph? Sentence? Word? And then have a look at some of php’s array and string functions to help you achieve this. I don’t think you could do this effectively in the database, but perhaps you could insert breaks when storing or authoring.
Try this:
<?php
$page = isset($_GET['page']) ? $_GET['page'] : 0;
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
$query = mysql_query("SELECT id, body FROM forum WHERE id=$id") or die(mysql_error());
$row = mysql_fetch_array($query);
$body = $row['body'];
function navigate($body, $qty, $page, $id)
{
$body_length = strlen($body);
$start = $page * $qty;
$endif = $body_length - $start;
echo substr($body, $start, $qty);
if (($body_length > $qty) and ($endif > $qty))
{
echo "...<br/>\
";
$page = $page + 1;
echo '<a href="test.php?page=' . $page . '&id=' . $id . '">+ more...</a><br/>';
}
}
navigate($body, 200, $page, $id);