Forum Moderators: coopster

Message Too Old, No Replies

Pagination

pagination on a full text article

         

ladams02

11:56 pm on Sep 18, 2006 (gmt 0)

10+ Year Member



Hey all,

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?

Birdman

6:16 am on Sep 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It would make more sense to utilize MySQL to grab substrings, one at a time. Especially if the text is large.

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]

whoisgregg

9:51 pm on Sep 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Won't substring chop words apart? This may just be my ignorance about SQL queries...

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.

henry0

10:45 pm on Sep 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



About 8 to 12 days ago something similar was addressed.

I guess we came with a solution ... too bad.. can't remember where.

wasn't it about creating an array, counting words etc..?

ladams02

3:49 pm on Sep 20, 2006 (gmt 0)

10+ Year Member



I've been searching up and down for a similar situation, but everything I've come across deals with paginating rows on a page, not from within a cell.

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 ...");

vincevincevince

5:27 pm on Sep 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can use regex in mysql - just look for /^.{1400,1500}\ / (i.e. anything for 1400 to 1500 characters so long as it ends with a space. Obviously you can change the space to a . or even one or the other etc...