Can somebody tell me how to add ... after a certain number of characaters that are pulled from a column in a MySQL database?
I've tried this but for some reason it isn't working:
LEFT('entry_excerpt', 40) as excerpt
| SitePoint Sponsor |





Can somebody tell me how to add ... after a certain number of characaters that are pulled from a column in a MySQL database?
I've tried this but for some reason it isn't working:
LEFT('entry_excerpt', 40) as excerpt
John Saunders
If you are using PHP, you can use this function I wrote a few years back:PHP Code:function shorten ($text, $charcount)
{
$text = substr($text, 0, $charcount);
$lastchar = substr($text, -1, 1);
if ($lastchar != '.')
{
$text .= '...';
}
return $text;
}
Brock Ferguson
Lead Developer, Caribou CMS
A Subscription/Membership CMS and Ecommerce Platform - FREE Trial


you can do it with mysql too
select concat(left(acolumn,40),'...') as excerpt, ...
you can also use CASE to check the length first so that if the value itself is less than 40 you don't concat the dots
Bookmarks