I am using Dreamweaver mx 2004, MYSQL & Php
I have a results page on my website that displays text from my database etc. I want to truncate one of the text fields so that it only displays the first 50 characters. I've heard that it can be done in MYSQL as follows:
SELECT LEFT(long_field, 50) AS preview FROM your_table
or alternatively in PHP as follows:
$preview = substr($whole_field, 0, 50);
My question is how to incorporate these functions into my sql queries/PHP Code:
SELECT *
FROM MyTable
WHERE MyField LIKE '%colname%'
<?php echo $row_rsRecordset['Myfield']; ?>
The preview function in sql does not seem to work well with the dreamweaver mx repeat region funtionality and just shows the first record on the database. I'd prefer to do this in PHP if possible. I'm quite new to coding so please be gentle with replies!
Truncation of fields from database
Moderator: General Moderators
RTFM
SELECT LEFT(colname,50)
FROM MyTable
WHERE MyField LIKE '%colname%'
Code: Select all
LEFT(str,len)
Returns the leftmost len characters from the string str.
mysql> SELECT LEFT('foobarbar', 5);
-> 'fooba'FROM MyTable
WHERE MyField LIKE '%colname%'