Forum Moderators: coopster

Message Too Old, No Replies

30 chars only

CMS output

         

FnTm

7:02 am on Aug 13, 2007 (gmt 0)

10+ Year Member



Hi!

So what I would like to have, is a script that outputs only 30chars from a database field, that contains more than 300.

It is for my newest articles list on my cms. Can it be done?
Can I output only 30 or less chars?

Habtom

7:43 am on Aug 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



substr

SELECT substr(text_long,0,30) AS text_short
FROM text_pool

Habtom

[edited by: Habtom at 7:44 am (utc) on Aug. 13, 2007]

FnTm

8:00 am on Aug 13, 2007 (gmt 0)

10+ Year Member



Yeah, i think it would work, but i am using * to output my results...

$result = mysql_query("SELECT * FROM cms ORDER BY id desc limit 5");

can I incorporate that command in here too?
[edit] it follows with these commands:
while($row = mysql_fetch_array($result))
echo "<td><br><font class=\"text\">".$row['title'] . ";

[edited by: FnTm at 8:03 am (utc) on Aug. 13, 2007]

Gian04

8:30 am on Aug 13, 2007 (gmt 0)

10+ Year Member



I think much better to use this one

echo mb_strimwidth($row['title'], 0, 30, "...");

dreamcatcher

8:31 am on Aug 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



echo "<td><br><font class=\"text\">".(strlen [php.net]($row['title'])>300? substr [php.net]($row['title'],0,30) : $row['title']).";

dc

Habtom

8:33 am on Aug 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$result = mysql_query("SELECT * FROM cms ORDER BY id desc limit 5");

> The easiest thing to do is to change * to the field names you have. Anyway, you are better off having the field names instead for several reasons.

If you want to keep it that way, you can use the substr function in PHP code itself.

$title = substr($title, 0, 30);

Habtom

FnTm

9:29 am on Aug 13, 2007 (gmt 0)

10+ Year Member



Thanks Habtom! really helped alot!