Limiting characters
Posted: Mon Mar 13, 2006 11:16 am
Question: Say I have a news article stored in my database and I want to just list the title and a brief exerpt from in on say an index page.
Can I create an additional variable based on $body (below) that says to just return the first 100 characters or the article?
Thanks
Can I create an additional variable based on $body (below) that says to just return the first 100 characters or the article?
Thanks
Code: Select all
$query = "SELECT title, body FROM news WHERE id=".$_GET['id'];
$result = mysql_query($query) or die('Error : ' . mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$title = $row['title'];
$body = $row['body'];
$content .= "<hr><a href=\"news.php\">< Back</a><hr>
<p><strong>$title</strong></p>
<p>$body</p><hr>
<p><a href=\"news.php\">< Back</a> - <a href=\"#top\">Top</a></p><hr>";