How can I Display an extract from MySQL database entry?

Posted by ThatMacLad on Stack Overflow See other posts from Stack Overflow or by ThatMacLad
Published on 2010-05-27T20:54:20Z Indexed on 2010/05/27 21:11 UTC
Read the original article Hit count: 99

Filed under:
|
|
|

I'm after creating a webpage that includes a blog section and it currently displays the whole post on the homepage. I'd like to set it so that it only displays a certain part of the entry i.e 50 words. I'd then like to be able to set it so that I have a read more button below the post that links to the post id. I currently use post.php?=# (# = whatever the post id is).

Here is the homepage:

<!DOCTYPE html> 
<html> 
<head> 
<meta charset="UTF-8"> 
<title>Blog Name</title> 
<link rel="stylesheet" href="css/style.css" type="text/css" /> 
<body>
    <div id="upper-bar">
    <div id="bar-content">

    <a href="#">Home</a>
    <a href="#">Archives</a>
    <a href="#">Contact</a>
    <a href="#">About</a>

    <a href="#"><img src="images/twitter.png" id="tweet"></a><a href="#"><img src="images/feed.png" id="feed"></a>
    </div>
    </div>

    <div id="clear">
    </div>


    <div class="main">
    <h1>Blog Name</h1>
    <div class="post-col">
    <?php
    mysql_connect ('localhost', 'root', 'root') ;
    mysql_select_db ('tmlblog');

    $sql = "SELECT * FROM php_blog ORDER BY timestamp DESC LIMIT 5";

    $result = mysql_query($sql) or print ("Can't select entries from table php_blog.<br />" . $sql . "<br />" . mysql_error());

    while($row = mysql_fetch_array($result)) {

        $date = date("l F d Y", $row['timestamp']);

        $title = stripslashes($row['title']);
        $entry = stripslashes($row['entry']);
        $id = $row['id'];

        ?>
         <div id='post-info'><?php echo "<p id='title'><strong><a href=\"post.php?id=". $id . "\">" . $title . "</a></strong></p>"; ?><br /></div>
               <div id="post">
               <?php echo $entry; ?>
               <!--<br /><br />
               Posted on <?php echo $date; ?> !-->
               </p>
               </div>


        </p>
    </div>    

        <?php
    }
    ?>
    </div>
     </div> 
</body> 
</html> 

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql