SitePoint Sponsor |
|
User Tag List
Results 1 to 2 of 2
Thread: MySQL select first paragraph
-
May 22, 2003, 11:42 #1
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.
-
May 22, 2003, 16:23 #2
- 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;
Example:
PHP Code:$text = '<p>blasdasdasdsad</p><p>asdsad</p>';
echo substr($text, 0, strpos('</p>', text));
Christian
Bookmarks