SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Sep 2001
    Location
    Vancouver
    Posts
    809
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Limiting characters - MySQL

    How do I add another statement in the code below, so that the "subject" field can also be limited to a certain number of characters:
    PHP Code:
    SELECT CONCAT(LEFT(article,100), '...') AS articleidtimesubjectdatesource
    FROM news
    ORDER BY time DESC
    LIMIT 0
    10 

  2. #2
    SitePoint Zealot
    Join Date
    Jun 2003
    Location
    Middle / East TN
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure in MySQL, but in PHP you can use substr() :

    $subject = substr($subject,0,10);
    There are 10 kinds of people in this world,
    those who can read binary and those who can't.

  3. #3
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    SELECT 
       CONCAT
    (LEFT(article,100), '...') AS article
       
    idtime
       
    CONCAT(LEFT(subject,100), '...') AS subject
       
    datesource
    FROM news
    ORDER BY time DESC
    LIMIT 0
    10 
    My name is Steve, and I'm a super-villian.

  4. #4
    SitePoint Guru
    Join Date
    Sep 2001
    Location
    Vancouver
    Posts
    809
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you!


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
  •