SELECTING a sentence from a text field?

From: Date: Tue, 14 May 2002 00:28:34 +0000
Subject: SELECTING a sentence from a text field?
Groups: php.db 
Request: Send a blank email to php-db+get-19171@lists.php.net to get a copy of this message
Hello all. I have a MySQL field called 'description' that contains a paragraph of text. I want to pull out the first 30 words (or there about) from 'description'. This is what I came up with: "SELECT ID, name, LEFT(description,95), IF(enrolling = 1,'Currently enrolling','') FROM trials ORDER BY name ASC LIMIT $offset, $limit" Obviously this grabs the first 95 characters from 'description', but when I display 'description' the word at the end of the string (after the 95th charter) is often cut right in the middle. I know that I could select the whole field then use a regex to chop the string at the first '.' but I would rather have a SQL statement that only grabs the text I need. So how do I write a SQL statement that will grab the first 30 words without chopping the last word? Thanks for your time. larry.

« previous php.db (#19171) next »