SitePoint Sponsor

User Tag List

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

    Is anyone of you kind people willing to help me???

    How I can combine a CONCAT query that limits the number of words to be displayed with one that sorts my results?

    Example:

    This one
    PHP Code:
    $num_words 60;
    $sql "SELECT CONCAT(SUBSTRING_INDEX(Text, ' ', $num_words), '...') as synopsis FROM News"
    with this one
    PHP Code:
    $result mysql_query(
                
    "select * from News, Authors, Categories WHERE  News.AID=Authors.ID AND News.CID=Categories.ID AND News.CID=1 ORDER BY Date LIMIT 1"); 
    in a single query.

    THANKS

  2. #2
    SitePoint Enthusiast Stallion's Avatar
    Join Date
    Jan 2001
    Location
    Cumberland, RI, US
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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"); 

  3. #3
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just kinda wondering what a "CONCAT" is?

  4. #4
    SitePoint Enthusiast Stallion's Avatar
    Join Date
    Jan 2001
    Location
    Cumberland, RI, US
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Concatination. In its most common form, it merges two strings into one.

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

    Thanks my friend

    You're a wizard, thanks a lot.

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

    But it didn't limit the words...

    showing on the query. Wonder why?

  7. #7
    SitePoint Enthusiast Stallion's Avatar
    Join Date
    Jan 2001
    Location
    Cumberland, RI, US
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have to access $record["synopsis"], not $record["Text"]...
    /* Chris Lambert - chris@php.net
    WhiteCrown Networks, CTO - Web Application Security
    vBulletin, Security Programmer - Instant Community
    */


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
  •