How To: Read More Link

Photo of Mike Dalisay
Modified Sunday, October 24, 2010
by - @ninjazhai
Creating a Read More link saves space in your page especially if you want to display a list of articles. It is much better than displaying the whole content of an article.

How To: Read More Link
Read More Link

Step 1: Prepare your database configuration file.

Step 2: Create your index.php file. You should have these codes.

include 'config_open_db.php'; // For database connection

// SUBSTR function in the query is used to shorten the output of the content
$sql = "select id, title, SUBSTR( body, 1, 300 ) as body from articles";
$rs = mysql_query( $sql ) or die( 'Database Error: ' . mysql_error());
while( $row = mysql_fetch_array( $rs ) ){
    extract( $row ); // to have variable names the same with column names
    echo "<h4>$title</h4>";
    echo "$body";
    // Link to the page where the reader can read the whole article
    echo "...[<a href='read_news.php?page_id=$id'>Read More</a>]";
For FREE programming tutorials, click the red button below and subscribe! :)
Thanks for the comments!
"First do it, then do it right, then do it better."
~ Addy Osmani
"Talk is cheap. Show me the code."
~ Linus Torvalds
Let's Stay Connected!
g+ r
Android app on Google Play
© 2011-2014 The Code Of A Ninja. All rights reserved. Proudly Powered by Google Blogger. Images, logos, marks or names mentioned herein are the property of their respective owners.