I have a MySQL database that stores a number of news items for my site. What I want to do is get the first 20 or so words from the database. I know you can get the first 20 or so characters, but how would I get the words ?
Thanks for any help
SELECT SUBSTRING_INDEX(contentfieldname, ' ', 20) as shortext from tablename;
If I were you, (although this is very inefficient), I would get the article whole, then in PHP write something that would return only what was before the 21st space (basically, 20 words .. although you might want to add some to count for spaces after periods and commas) but don't ask me how, 'cause I haven't got a clue.
Ask freddydoesphp ... feline knowledge always helps.
I say doing it in the query is not only accurate but more efficient.
So do I ! Darnit why do these amateurs always try and come up with half-baked, low-quality solutions. It's REALLY ANNOYING ;)
aherm. So do I... but somehow my glasses must have fogged up as I read the thread because I didn't notice freddy's reply when I replied ...
Hehe ... sorry 'bout that