Page 1 of 1

Truncation of fields from database

Posted: Sun May 16, 2004 8:26 am
by royalblue
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!

Posted: Mon May 17, 2004 9:05 am
by lostboy
RTFM

Code: Select all

LEFT(str,len) 
Returns the leftmost len characters from the string str. 
mysql> SELECT LEFT('foobarbar', 5);
        -> 'fooba'
SELECT LEFT(colname,50)
FROM MyTable
WHERE MyField LIKE '%colname%'

Posted: Mon May 17, 2004 2:37 pm
by royalblue
Thanks for reply but this funtion doesn't seem to work witha 'repeat region' server behaviour in dreamweaver - it just keeps returning the same field over and over again. Is there any way of doing this in php?

Posted: Tue May 18, 2004 2:10 pm
by royalblue
Have now got this working - Many thanks for your help !