SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Git-R-Done
    Join Date
    Nov 2001
    Posts
    1,194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to add ... after # of characters?

    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

  2. #2
    SitePoint Enthusiast
    Join Date
    May 2004
    Location
    Ontario, Canada
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you are using PHP, you can use this function I wrote a few years back:
    PHP Code:
    function shorten ($text$charcount)
    {
        
    $text substr($text0$charcount);
        
    $lastchar substr($text, -11);
        if (
    $lastchar != '.')
        {
            
    $text .= '...';
        }
        return 
    $text;

    Brock Ferguson
    Lead Developer, Caribou CMS
    A Subscription/Membership CMS and Ecommerce Platform - FREE Trial

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,323
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    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
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •