Urgent:Is there alternative to substr?:

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
tovia2000
Forum Newbie
Posts: 12
Joined: Sat Aug 25, 2007 7:45 am

Urgent:Is there alternative to substr?:

Post by tovia2000 »

Is there an alternatiuve to substr,

My problem:

I need to extract only the first 30 words from my body column from my mysql database table, for displaying on my pagination page,


Liek these gys do it down teh center of there page:, and display ... after some text:

http://www.articlealley.com/


how can i do this with top performance, i ahev thousands of records, is substr the only way?


Thanks in advance

kind regards


Tovia Singer
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

you do want substr(), just not PHP's substr()!

MySQL's SUBSTR()
http://dev.mysql.com/doc/refman/5.0/en/ ... _substring

Or, if you prefer the first so many words:
http://dev.mysql.com/doc/refman/5.0/en/ ... ring-index
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Post by califdon »

Kieran Huggins wrote:Or, if you prefer the first so many words:
http://dev.mysql.com/doc/refman/5.0/en/ ... ring-index
That's a very useful SQL function that I'd never noticed before! Thanks, Kieran.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

For the record, substr is also available in Sybase.

PS I am moving this to Databases until it become clearly evident that this is a PHP Code question.
Post Reply