Forum Moderators: coopster
SELECT SUBSTRING(my_text, 1, 500) FROM mytable;And/or you could use PHP to show only that portion of the string. A recent thread [webmasterworld.com] describes some options.
mysql> SELECT SUBSTRING_INDEX('This is a few words', ' ', 2);
returns 'This is'
SELECT substring_index(mytext,' ',500) as preview, otherfield1, otherfield2 from mytable;
is what I would do.
I agree with Netizen, if you're only going to display the first 500 words, don't waste any more resource by grabbing the whole column again. Worry about that if the user actually follows the link ;)
$query = "SELECT SUBSTRING_INDEX(testimonial,' ',500) FROM testimonials WHERE id = '$id'";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
SELECT substring_index(mytext,' ',500) as preview, otherfield1, otherfield2 from mytable;
Thanks!
$query = "SELECT SUBSTRING_INDEX(testimonial,' ',500) AS preview
FROM testimonials WHERE id = '$id'";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
while ($row = mysql_fetch_assoc [php.net]($result)) {
print $row['preview'];
}