php_newB Posted March 18, 2007 Share Posted March 18, 2007 Hi I am a php newbee and I am building a CMS which stores articles in a database. I know how to display the whole article but what I want to do is to get an article from the database and display the first 4 lines of that article with a link for readers to read the whole article. so I was wondering is there anyway way to do this. Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/43239-display-first-4-lines-of-an-article/ Share on other sites More sharing options...
ignace Posted March 18, 2007 Share Posted March 18, 2007 sure their is, no problem xD because you did not provide any code, i will be using assumptions <?php // assuming we are connected to a database with type MySQL // and we have already queried the database, and saved that in a variable called $result... while ($row = mysql_fetch_assoc($result)) { echo substr($row['article_body'], 0, 186) . "..."; // displays 186 characters from your article printf("<p><a href='article.php?id=%s'>Read More</a></p>", $row['article_id']); // the read more link } // adjust to your own needs, it is not the best example but it should get you started // from programmer to programmer, i would also give you the advice to "abuse" the search function option // on www.php.net, so you can look up functions and what they do, like substr() for exampe! ?> Quote Link to comment https://forums.phpfreaks.com/topic/43239-display-first-4-lines-of-an-article/#findComment-209978 Share on other sites More sharing options...
php_newB Posted March 18, 2007 Author Share Posted March 18, 2007 Thanks ignace for your reply, I'll take your advice and look at php function in future. As I said I am a newB and trying to learn php but I accept I have been a bit lazy !! Thanks again for your help Quote Link to comment https://forums.phpfreaks.com/topic/43239-display-first-4-lines-of-an-article/#findComment-210007 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.