Reputation: 531
I have a MySQL table with a field named description
, with a record like this:
Former cop Brian O'Conner partners with ex-con Dom Toretto on the opposite side of the law.Since Brian and Mia Toretto broke Dom out of custody, they've blown across many borders to elude authorities. Now backed into a corner in Rio de Janeiro, they must pull one last job in order to gain their freedom. As they assemble their elite team of top racers, the unlikely allies know their only shot of getting out for good means confronting the corrupt businessman who wants them dead. But he's not the only one on their tail. Hard-nosed federal agent Luke Hobbs never misses his target. When he is assigned to track down Dom and Brian, he and his strike team launch an all-out assault to capture them. But as his men tear through Brazil, Hobbs learns he can't separate the good guys from the bad.
How can I display first 200 characters of it? Like this:
Former cop Brian O'Conner partners with ex-con Dom Toretto on the opposite side of the law.Since Brian and Mia Toretto broke Dom out of custody, they've blown across many borders to elude authorities.
Upvotes: 5
Views: 2694
Reputation: 57593
Try this:
SELECT SUBSTR(description, 1, 200)
FROM your_table
You can find docs here
Upvotes: 6
Reputation: 792
SELECT SUBSTRING(`description`,1,200) as description FROM table
That will start at position 1 and go 200 characters, and return the field as 'description' which is easier for mysql_fetch_assoc()
Upvotes: 2
Reputation: 146310
SELECT * FROM table ...
Then in PHP just:
echo substr($desc, 0, 200); //1st 200 characters
Upvotes: 2
Reputation: 455302
It is better to get the substring from the database rather than getting the whole string into PHP and then slicing it:
SELECT SUBSTRING(description, 0, 200) FROM TABLE_NAME
Upvotes: -1