SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Help Please!!!

  1. #1
    SitePoint Enthusiast Yonko's Avatar
    Join Date
    Jun 2001
    Location
    Panama
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help Please!!!

    How do I limit the text I'm pulling from the db by number of words? Please help. Thanks

  2. #2
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There isn't a built in function for number of words, so you can't do it.

    You can do it by characters however using the SUBSTRING() Function. As in this example:

    SUBSTRING(Chp_Text, 50, 100);

    The first parameter is the field, the second is the character number to start at, the third is the number of total characters you want returned.

    Once you get this if you don't want it cut off in the middle of a word you can check the beginning and end of a string and chop off the extra characters until you reach a space.
    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums

  3. #3
    SitePoint Enthusiast Yonko's Avatar
    Join Date
    Jun 2001
    Location
    Panama
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    So this function of mine...

    PHP Code:
    $num_words 60;
      
    $result mysql_query(
                
    "SELECT *, CONCAT(SUBSTRING_INDEX(News.Text, ' ', $num_words), '...') AS synopsis FROM News, Authors, Categories WHERE News.AID=Authors.ID AND News.CID=Categories.ID AND News.CID=1 ORDER BY Date LIMIT 1"); 
    won't cut it?


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
  •