Re: Paged Results Set in MySQL DB with one result

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

 



At 07:12 AM 5/4/2006, tedd wrote:
If the text is organized into paragraphs, which I can't imagine it not being, then the solution can be found in using a combination of javascript and php.

Javascript can detect the size (height & width) of window the user is currently using and the web site has control over the font size and margins. With that information, via ajax, it's certainly solvable to calculate what text would fit into the space provided and display it in real time.

Granted it would make for a boring presentation because no titles or variations in font sizes, but if someone wanted to simply throw text to an open window, one could calculate how many paragraphs would fit in the available space and the users actions (on-load, window-resize) could trigger the operation.

Furthermore, if headings where identifiable, then those could be thrown into the mix and calculated as well.


Yes: cutting text into arbitrary column-lengths is most likely a client-side task and therefore not on-topic for this list, but since you've opened the door...

Headlines and other variations in text size need not be a problem. No need to calculate rendered text size: let the browser do it.

The way I might approach this is to feed more text to the page than I know will fit, enclose it in a container that JavaScript sets to {overflow: hidden}, and use JavaScript to detect where (at which paragraph and word) the visible text block ends.

One way to find the last visible word would be to enclose a word in a span, compare its rendered position to the height of the text container, remove the span, and continue until we find a word that's lower than the bottom of the container. The most efficient way to perform this search might be to check the first word of each paragraph until a hidden word is found, then work backward from there. Once JavaScript had determined the last word on the rendered page (or the first word to be displayed on the next page), it would communicate this to PHP -- either immediately [via new Image() src or XMLHttpRequest] or on the next page request through the navigation hyperlinks or form submit.

To accommodate font-resizing, JavaScript could set a self-timer to re-check the last visible & first hidden words on the page and see if their 'shown' status had changed. If it has, all it has to do is report the new page boundary to PHP.

This would have to work in the absence of client-side scripting, so it's JavaScript that sets {overflow: hidden} on the text container.

This technique could also be used to flow text across multiple columns. I don't know how close it comes to existing techniques of calculating text-column-length.

In my Copious Spare Time I'll do a proof of concept to see how this flies.

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