SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict seanmayhew's Avatar
    Join Date
    Aug 2002
    Posts
    209
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MySQL select first paragraph

    I have a story lead on my front page that I just want to display the author name and the first paragraph of that authors most recent story. Should I just create a field in my database that contains the lead. Or is there a way to select just the first paragraph of the article.

  2. #2
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use mysql substring(text, start, end) if you know how many characters to extract.

    Code:
    SELECT Substring(articletext, 0, 20) AS abstract FROM yourtable 
    WHERE authorid = 1
    ORDER BY publisheddate
    LIMIT 1;
    You can also use PHPs function substr() and strpos() in connection to get the first paragraph.

    Example:
    PHP Code:
    $text  '<p>blasdasdasdsad</p><p>asdsad</p>';

    echo 
    substr($text0strpos('</p>'text)); 
    Maybe you have to add the length of the search word (here </p>) to the number returned by strpos.

    Christian


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
  •