Forum Moderators: open

Message Too Old, No Replies

[SQL] Deleting <i> </i> around " and "

         

sarka86

7:50 am on May 1, 2008 (gmt 0)

10+ Year Member



Good morning!

I have a table T with 3 fields A, B and C that contain text.
Sometime the text contains quotation and sometimes the quotation is inserted in tag <i> </i>. I'd like to write a query that update any field in which '<i>"*"</i>' occurs into '"*"'.

Is it possible to do that with mySql? Or should I write a PHP program? What is the fastes/most elegant way?

Thank you a lot for your attention!

ashish21cool

8:53 am on May 1, 2008 (gmt 0)

10+ Year Member



you should use replace () function

sarka86

1:11 pm on May 1, 2008 (gmt 0)

10+ Year Member



Hallo and thank you for your reply.
I've read about this replace function, but I didn't get how I am supposed to use it in an update query.

ashish21cool

3:50 am on May 2, 2008 (gmt 0)

10+ Year Member



Is it necessary to use in the update query. You can use it directly as well and change the strings.

Is you string '<i>"*"</i> residing in a particular column or it is in any column?

ashish21cool

4:06 am on May 2, 2008 (gmt 0)

10+ Year Member



you might use this
update table_name=
set colum_nmae = REPLACE('abcdefghicde','cde','#*$!');

output
ab#*$!fghi#*$!

sarka86

1:54 pm on May 2, 2008 (gmt 0)

10+ Year Member



Hallo!

Now I got the main idea. Thanks.
I have a field in which <i> </i> can be contained.
But I'd like that the text of the field is the 1st argument of replace.
Something like:

update myTable = set myField = REPLACE(SELECT note FROM canzoni,'<i>','');

Of course that doens't work.
With PHP I could do:

$ptr = mysql_query("SELECT myField, id FROM myTable");

// ...inside the reading loop with $myArr the array that stores DB data
mysql_query("UPDATE myTable = set myField = REPLACE($myArr[0], '<i>', '') WHERE id=$myArr[1]");
mysql_query("UPDATE myTable = set myField = REPLACE($myArr[0], '</i>', '') WHERE id=$myArr[1]");

But I'd prefer to write a single query once and for all. Is that possible?

Thanks!

ashish21cool

4:30 am on May 3, 2008 (gmt 0)

10+ Year Member



I actually did not get you question.

If possible please ellaborate for more understanding. An example would be better to understand.