Jump to content

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/43239-display-first-4-lines-of-an-article/
Share on other sites

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!
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.