0

I'm trying to display a certain amount of words on one page from a database entry. For ex., on my main page I want to display the first 50 words of a story then a link will lead you to the rest of the story. I kind of know what I need to do but I don't know where to put the code. I want to display the first 50 words from 'story'. Here is my code.

<center>
<table width="760" border="3" bordercolor="ffffff" cellspacing="1" cellpadding="0">

<?
include("dbinfo.inc.php");
mysql_connect("nldesign.startlogicmysql.com",$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM news ORDER BY ID DESC LIMIT 0, 1";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

?>

<?
$i=0;
while ($i < $num) {
$headline=mysql_result($result,$i,"headline");
$story=mysql_result ($result,$i,"story");
$id=mysql_result($result,$i,"id");
?>

<tr>
<td bgcolor="ffffff" width="400" valign="top"><img src="mainpic.jpg"></img></td>
<td bgcolor="ffffff" width="360" valign="top"><h4><? echo "$headline"; ?></h4><h3><? echo "$story"; ?></h3><a href="view_story.php?id=<? echo "$id"; ?>" style="text-decoration:none"><h5>read more...</h5></a></td>
</tr>

<?
++$i;
}
echo "</table>";

?>
</center><br>
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by iamthwee
0

I'm not sure if you can do this purely with MySql.

My initial gut feeling would be to store the text in an array and then use php to count the words. Words are delimited by whitespace.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.