Posted by: prajapatinilesh | August 9, 2007

MySQL Lead-In Sentence fragment…

As a “preview” of text, this MySQL select will return the first few words out of a text field in a database. It returns entire words (doesn’t cut them off in the middle) and follows the last word with an elipse “…”

In the PHP, assign $CharactersToDisplay to a number – the approximate number of characters desired (or you can hard-code it if you want).

For the example, I also use $TheID as the row identity for the record to display.

SELECT CONCAT(LEFT(NameOfTextField,LOCATE(‘ ‘,NameOfTextField,$CharactersToDisplay)-1),‘…’)
FROM TheTable
WHERE TheID = $TheID

Advertisements

Responses

  1. Thanks really very useful


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: