Re: Paged Results Set in MySQL DB with one result

From: Date: Thu, 04 May 2006 09:11:43 +0000
Subject: Re: Paged Results Set in MySQL DB with one result
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-235454@lists.php.net to get a copy of this message
On Wed, May 3, 2006 1:51 pm, Phillip S. Baker wrote: > I have an interesting problem I would like some ideas on for a > solution. > I cannot seem to find any code examples on the net, though I might not > be looking in the right place really. > > 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. > > I know about pulling paged results using the limit function but that > would not seem to apply as really I would want to page the results > within one record (one field really). It's pretty much the same as paging through records, but instead of: LIMIT $limit OFFSET $offset you would do: SELECT substring(monster_text, $offset, $limit) FROM whatever You will probably then want to dink around with things so that you don't break your text up in mid-word, but you can do that fairly easy on the PHP end once you have the chunk of text with http://php.net/strrpos: $pos = strrpos($text, ' '); $next_offset = $offset + $limit - ($limit - $pos); $text = substr($text, 0, $pos); There's probably an off-by-one error in that, but you get the idea. -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#235454) next »