Forum Moderators: coopster

Message Too Old, No Replies

Help with displaying results from MySql

From php beginner.

         

ski442

8:59 pm on Apr 1, 2007 (gmt 0)

10+ Year Member



Hi All.
Can anyone tell me if it is poss to display only 1/3rd of a feild in db. My feild is called Description and has the text would only like to show part of this results in a quick veiw page.
can i add somthing to this code?

echo '<p>' . $row ['discription'] . '</p>';

maccas

9:15 pm on Apr 1, 2007 (gmt 0)

10+ Year Member



You can do it by number of characters, i.e below would display 25 characters followed by ...
$length = 25;
$shortdiscription = substr_replace($row ['discription'], '...', $length);
echo '<p>' . $shortdiscription . '</p>';

[php.net...] or [php.net...]

maccas

9:27 pm on Apr 1, 2007 (gmt 0)

10+ Year Member



This should be a 1/3

$length = round(strlen($row['discription'])/3);
$shortdiscription = substr_replace($row['discription'], '...', $length);
echo '<p>' . $shortdiscription . '</p>';

ski442

9:34 pm on Apr 1, 2007 (gmt 0)

10+ Year Member



Thanks Maccas
the fisrt is fine as the amount of text shown is not a real problem just wanted to reduced some what to save having a huge page.

So your first post is more that helpfull as can change charactar amounts.

Will be woking on the Limit clause next so will be back in a few days i reckon.
Thanks again.