justuptime.com - monitor your servers & websites

Truncating Database text

You are viewing this site as a guest. Join our community to get your questions answered and share knowledge. Active members may advertise and ask for a website critique.
mjs416's picture

They have: 127 posts

Joined: Dec 2003

I have a MYSQL database table with some text fields. I have these fields (or the text in it rather) being output to a php page. The text field is of the type "longtext".

How do I truncate the text displayed when it is being browsed by someone?

For exmple, say the text field in the database has "abcdefghijklmnopqrstuvwxyz". Yet when someone is trying to view it, only the "abcdefg" text is displayed.

__________________________________
SkrekLAN Technologies
www.skreklan.com

Greg K's picture
Moderator

He has: 1,601 posts

Joined: Nov 2003

In your SQL query itself you can do the following:

$query = "SELECT LEFT(fieldname,7) FROM table";

In the server side script itself, assuming the data you want to truncate is in variable:

in PHP, substr(variable,0,7);

in ASP, not sure, but if it's like VB, left(variable,7)

-Greg

[This space intentionally left blank]

Cool Geek Supplies: www.ThinkGeek.com

mjs416's picture

They have: 127 posts

Joined: Dec 2003

Splendid. Thank you very much. =)

openmind's picture

He has: 943 posts

Joined: Aug 2001

or in ColdFusion:

#Left(variable, 7)#

just wanted to round off the choices! Laughing out loud

Cheers,
Phil
[b]HelmStore.com
UK Distributor of HELM Licenses
Suppliers of SmarterTools, Backup for Workgroups licenses and much, much more![/b]