Forum Moderators: coopster

Message Too Old, No Replies

Newbie question

I need to truncate data in one field

         

andrewshim

10:56 pm on Oct 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a mySQL table with a particular field that contains multiple phrases. I would like to REMOVE the first 15 characters in the field. I don't know how to do it. Do I use something like :

UPDATE table set field = substr(field,15,25)

?

eelixduppy

1:57 am on Oct 13, 2006 (gmt 0)



Almost. It would be more something like this:

$query = "UPDATE table_name SET field = '".[url=http://us3.php.net/manual/en/function.mysql-real-escape-string.php]mysql_real_escape_string[/url](substr($text,15))."'";

Best of luck :)

P.S. The reason I omitted the '25' in the substr function is because you only want to remove the first 15 characters. By putting the 25 there you are also limiting the length of the string to 25 characters.

andrewshim

2:37 am on Oct 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hi eelixduppy...

$query = "UPDATE table_name SET field = '".mysql_real_escape_string(substr($text,15))."'";

errr... I'm using PHPmyadmin.

- Do I need to use the "query =" and the "quotes" sections?

- is $text the text that I want removed?

eelixduppy

2:42 am on Oct 13, 2006 (gmt 0)



Oh I'm sorry. I figured that you were running this query through PHP considering this is a PHP forum ;)

Here's the corrected syntax for MySQL:


UPDATE table_name SET field = SUBSTRING(field,15);

andrewshim

6:13 am on Oct 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I wasn't sure if I was in the right place but anyway... it works fine... thanks ever so much!