Truncating Database text
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.
Greg K posted this at 17:22 — 8th December 2004.
He has: 2,145 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
mjs416 posted this at 17:27 — 8th December 2004.
They have: 127 posts
Joined: Dec 2003
Splendid. Thank you very much. =)
openmind posted this at 18:22 — 8th December 2004.
He has: 945 posts
Joined: Aug 2001
or in ColdFusion:
#Left(variable, 7)#
just wanted to round off the choices!
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.