I have a news feature on a website and have a page that shows all of the news and a link to the actual page of each individual news. On first page that lists all the news i would like to limit the amount of Characters that is echoed from the database field. So from the code below where it states

echo $row;

that is where i need to limit the amount of characters

if you could help that would be great.

$result = mysql_query("SELECT * FROM news ORDER BY id desc") 
or die(mysql_error());  

echo "<table class = feature >";
echo "<tr> <th></th> <th></th> <th></th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
	// Print out the contents of each row into a table
	echo "<tr><td>";
	echo $row['Date'];
	echo "</td><td>";
	echo "<a href='".$row['Link']."'>".$row['Title']."</a>";
	echo "</td><td>";	 
    echo $row['News'];
	echo "</td></tr>";
echo "</table>";
6 Years
Discussion Span
Last Post by P0lT10n

Do you want to hard limit it to x charachters, or do you want to split it up by the nearest word? Also, does the string contain any kind of formatting/html?


Firstly thanks for your reply.

I would prefer say 20 words and the formatting is all in paragraphs eg html <p> </p>


I know there is a code for input type text maxleng, but for p you ha ve to

$string = split("your text", 20);
echo $string;

I dont remember well how the command must be write...

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.