Hi,
I am working on a short story database using PHP and MySQL, but having problem with displaying a story with content's length larger than 2 pages.
If I just display the whole story on one single page, then it would be easy but that page is too long. I would like to break that page into pages, but have no idea how to. I've already know how to paginate a query result, but this case is different in that it only break content of of a single attribute in the table of the database.
Any suggestion will be appriciated!
Thanks!
How to paginate the content of a single attribute??
Moderator: General Moderators
- greenhorn666
- Forum Commoner
- Posts: 87
- Joined: Thu Aug 14, 2003 7:14 am
- Location: Brussels, Belgium
I would create a function that puts let say <newPage> (or even <page number="1">...</page> tags within the story depending on a threshold you define.
Let say max 1000 chars per pages, it then looks for the best place to cut the actual page (let say at the end of the last paragraph before the 1000 chars, or if that's below a 800 chars limit, a sentence's end.
Iterate while there are pages left...
When someone wants to view a story, it splits the story according to these tags...
Actually I think I would save the story in some nice XML inside the database, formatting that depending on page and otherthings would be more than easy then...
Again, you could apply this function I told you on the fly as a user views a story's page on the raw input from the database. This would raise load, but you would have raw data in the database.
I would go for the XML formatting if I where you. You could format pages, titles, paragraphs and whatever else is requested. Still stripping back to raw output would be not overkill.
Let say max 1000 chars per pages, it then looks for the best place to cut the actual page (let say at the end of the last paragraph before the 1000 chars, or if that's below a 800 chars limit, a sentence's end.
Iterate while there are pages left...
When someone wants to view a story, it splits the story according to these tags...
Actually I think I would save the story in some nice XML inside the database, formatting that depending on page and otherthings would be more than easy then...
Again, you could apply this function I told you on the fly as a user views a story's page on the raw input from the database. This would raise load, but you would have raw data in the database.
I would go for the XML formatting if I where you. You could format pages, titles, paragraphs and whatever else is requested. Still stripping back to raw output would be not overkill.
- greenhorn666
- Forum Commoner
- Posts: 87
- Joined: Thu Aug 14, 2003 7:14 am
- Location: Brussels, Belgium
There are pros and cons to this...
Is the DB backend on the same node as the webserver?
Well I would do it the XML way, do it the table way if you want, but I think it will slow down the process. Actually you would have to think a bit about what your priorities are on this project. What will be the fastest and lightest? Only him can answer these question, since he does know facts!
But I believe a chapter table is over kill! Like actually a database for storing the story is probably overkill...
Why don't you save infos on the story (date of submition, who read it and how it was rated by readers, infos on the author and such) in the database, but the story itselfs on the FS you could split things like
stories/{$style}/{$authorId}/{$storyId}.xml
I don't really see the point in storing it in a DB... Even if you would like to be able to query stories for specific words, I would rather index my XML files, than store them in a DB (cause that way you would only reindex on new submitions, or even less, every night; that way reducing load and could care for noise words)
Just a thought...
Is the DB backend on the same node as the webserver?
Well I would do it the XML way, do it the table way if you want, but I think it will slow down the process. Actually you would have to think a bit about what your priorities are on this project. What will be the fastest and lightest? Only him can answer these question, since he does know facts!
But I believe a chapter table is over kill! Like actually a database for storing the story is probably overkill...
Why don't you save infos on the story (date of submition, who read it and how it was rated by readers, infos on the author and such) in the database, but the story itselfs on the FS you could split things like
stories/{$style}/{$authorId}/{$storyId}.xml
I don't really see the point in storing it in a DB... Even if you would like to be able to query stories for specific words, I would rather index my XML files, than store them in a DB (cause that way you would only reindex on new submitions, or even less, every night; that way reducing load and could care for noise words)
Just a thought...