[thelist] MySQL extracting a teaser from a text field

Anthony Ettinger apwebdesign at yahoo.com
Mon Aug 22 17:40:16 CDT 2005


Do you have to get everything up to the first period?

You could just grab the first 20 characters.

Otherwise, I would select all, and then finesse the
results in the code.



--- "Noah St.Amand" <noah at tookish.net> wrote:

> I'm trying to find the best way to extract a teaser
> from a text field in 
> MySQL. Most of the time I can just take the first
> sentence, like this:
> 
> SELECT SUBSTRING(body, 1, LOCATE('.',body,'10')) AS
> teaser FROM table 
> WHERE id = 1;
> 
> That finds the first period more than ten characters
> in, and returns 
> everything up to and including that period.
> 
> The problem is that the field doesn't always contain
> a period, in which 
> case this query comes back empty.
> 
> I could run a separate query to look for a period
> before I execute this 
> query, then if no period is found just select a
> certain number of 
> characters, but that would require a bunch of PHP,
> and I'd rather do it 
> all in the SQL if possible.
> 
> Unfortunately this has to work in MySQL 3.23, so
> subqueries aren't an 
> option.
> 
> Any ideas?
> 
> Thanks,
> Noah
> -- 
> 
> * * Please support the community that supports you. 
> * *
> http://evolt.org/help_support_evolt/
> 
> For unsubscribe and other options, including the Tip
> Harvester 
> and archives of thelist go to:
> http://lists.evolt.org 
> Workers of the Web, evolt ! 
> 


Anthony Ettinger
ph: (408) 656-2473
blog: http://www.chovy.com

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


More information about the thelist mailing list