SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: MySQL Question

Hybrid View

  1. #1
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    I have a MySQL database that stores a number of news items for my site. What I want to do is get the first 20 or so words from the database. I know you can get the first 20 or so characters, but how would I get the words ?

    Thanks for any help
    Sean

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How about:

    SELECT SUBSTRING_INDEX(contentfieldname, ' ', 20) as shortext from tablename;
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Addict
    Join Date
    Nov 2000
    Location
    London, UK
    Posts
    223
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I were you, (although this is very inefficient), I would get the article whole, then in PHP write something that would return only what was before the 21st space (basically, 20 words .. although you might want to add some to count for spaces after periods and commas) but don't ask me how, 'cause I haven't got a clue.
    Ask freddydoesphp ... feline knowledge always helps.

    ... what's the world coming to?

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I say doing it in the query is not only accurate but more efficient.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I say fredddy is right.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  6. #6
    SitePoint Addict
    Join Date
    Nov 2000
    Location
    London, UK
    Posts
    223
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So do I ! Darnit why do these amateurs always try and come up with half-baked, low-quality solutions. It's REALLY ANNOYING
    aherm. So do I... but somehow my glasses must have fogged up as I read the thread because I didn't notice freddy's reply when I replied ...
    Hehe ... sorry 'bout that

    ... what's the world coming to?


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
  •