Re: Paged Results Set in MySQL DB with one result

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At 11:51 AM 5/3/2006, Phillip S. Baker wrote:
I have some articles stored in a MySQL DB.
What I want is if the article is above a certain length in characters, to page article through a few pages for site readability.

So I would want to print X number of words/characters.
Save the where the pointer is, move on to the next page, and display the same amount and so on for as many pages as needed.


Phillip,

There's a fundamental problem with trying to slice text into resizable web pages the same way it's sliced on paper. Paper pages work because they're set in a fixed font size. When you change the ratio of font size to column width, the places where lines of text wrap changes. Because of the varying lengths of words, strings of words spill over to the next line in non-linear rates. Unless you use a fixed font size (boo, hiss) or you change the font size and the column width at exactly the same rate by sizing your layout in ems, your text columns are going to change in height (line-count) with font resizing.

This means that the amount of text that fits on a page changes dynamically with browser events and cannot be predicted or controlled server-side by PHP -- unless you can accept a layout sized in ems both horizontally and vertically, which few people seem willing to do, or you force your readers to accept your choice of font size, which would be an ironic and depressing decision for a modern publisher to make.

Here's a related problem: Say you calculate the number of words that can fit in N column inches and dish out that much text from your database, and let's say that the last line on the page is in mid-paragraph. When the user resizes their browser font, the word-wrap will change and suddenly the last line on the page will end halfway across the column even though it isn't the end of the sentence or the paragraph.

In addition, all this means dynamically changing widows and orphans, also of concern to the serious typographer.

As a final coup de grace, any calculation of words per line must take into account the metrics of the specific font being rendered, a practical impossibility when fonts are selected from the users' computers and not the publisher's.

While PHP and MySQL can supply the raw text from the server, these issues beg for a client-size solution at the reader's end.

My first choice of solution would be to size my columns in ems to allow the entire layout to zoom both horizontally and vertically with font-size, in which case your problem of how to extract contiguous text strings again becomes relevant. And that's trivial, really, compared to the algorithm you'll have to write to predict how many words will wrap into a given number of lines when you can't even predict the font being used.

You could make the problem much more solvable by dishing up whole paragraphs only, and learning to accept (nay, embrace!) the resultant variation in page-length.

Paul
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux