Just the first 100 characters of a query
Posted: Thu Oct 06, 2005 3:48 pm
So I have some text in a mysql database value, but I don't want to display all of it. What's the command to only return the first so many letters from it?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
$dbEntryTeaser = substr($dbEntry, 0, 100);
echo $dbEntryTeaser;Code: Select all
SUBSTRING(str,pos) , SUBSTRING(str FROM pos) , SUBSTRING(str,pos,len) , SUBSTRING(str FROM pos FOR len)
mysql> SELECT SUBSTRING('Quadratically',5);
-> 'ratically'
mysql> SELECT SUBSTRING('foobarbar' FROM 4);
-> 'barbar'
mysql> SELECT SUBSTRING('Quadratically',5,6);
-> 'ratica'
mysql> SELECT SUBSTRING('Sakila', -3);
-> 'ila'
mysql> SELECT SUBSTRING('Sakila', -5, 3);
-> 'aki'
mysql> SELECT SUBSTRING('Sakila' FROM -4 FOR 2);
-> 'ki'
SUBSTR() is a synonym for SUBSTRING(), added in MySQL 4.1.1.Code: Select all
SELECT
SUBSTRING(long_field_value,0,100)
FROM
myTableUseful Posts wrote:Chopping of text without losing words: chopping of text