Forum Moderators: coopster
All the articles/tutorials I've found on pagination always refer to paginating multiple rows out of a database. Like displaying 5 rows on each page. But I'm trying to paginate an article that is being stored in one row of the table.
I'm pulling an article from the "content" cell out of the "entries" table. And want the article to display something like 1500 chars or 15 lines on a page. Should I try to limit the chars I pull out of the database, or put the entire article in a variable first and then try to cut the variable down to the size I need to display on each page?
The query would go like this:
select substring(content, 1500, 0) from entries where ...
Which would give you 1500 chars, starting at position 0.
You can use PHP to pass in the new offset on each page (eg 1500, 3000, etc.)
[edited by: Birdman at 6:18 am (utc) on Sep. 19, 2006]
I'm pretty sure if you are worried about word breaks, sentence breaks, or paragraph breaks, you'll want to do the breaking apart in PHP. To make it quick for the user, you could run the processing ahead of time and populate a DB with the broken apart chunks.
Building off of what Birdman suggested, I thought about using
$content2=mysql_fetch_row(mysql_query("SELECT SUBSTRING(contents,1,1500) FROM ..."); to grab the first 1500 chars, then searching within these chars for a </p> using $position=strrpos(content2, '</p>'); to find the last occurance of a </p>. Then once I have the cutoff position I want, go back and grab just that from the DB using
content2=mysql_fetch_row(mysql_query("SELECT SUBSTRING(contents,1,".$position.") FROM ...");