Forum Moderators: coopster

Message Too Old, No Replies

PHP script to update table from ascii charcter to

PHP script to update table from ascii charcter to

         

photocroatia

1:40 pm on Dec 26, 2004 (gmt 0)

10+ Year Member



I am trying to update a table, the table has two columns, col_a and col_b

I am trying to update col_b where any of the values have an ascii value of č to c.

I have tried both replace and translate

$sql="update table_name set col_b = replace(col_b,'č','c')";

This seem to only work if the value is č and not if č exists in the string.

I want to replace all occurances of č to "c"

I appreaciet your help, thank you.

coopster

7:59 pm on Dec 26, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member




This seem to only work if the value is č and not if č exists in the string.

The syntax is correct and works in my tests.

SELECT col_b FROM table_name; 
+-------------------------+
¦ col_b ¦
+-------------------------+
¦ this is the č text ¦
¦ č ¦
+-------------------------+
UPDATE table_name SET col_b = REPLACE(col_b,'č','c');
SELECT col_b FROM table_name;
+--------------------+
¦ col_b ¦
+--------------------+
¦ this is the c text ¦
¦ c ¦
+--------------------+
What does your data look like and what do you want it to look like?

photocroatia

12:54 am on Dec 27, 2004 (gmt 0)

10+ Year Member



Yes it works if only č exists but not if its in the text for example 'This is a test with č in the text"

If I run the update on this row it doesn't work.

Anpther example could be "Amother text with č in teh text , and one more occurance of č"

coopster

4:14 am on Dec 27, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



What database and version? As you can see, it worked fine for me. I ran the test on a MySQL database, version >= 3.23.58.
create table table1 (col_b char (40)); 
insert into table1 values('this is the č text');
insert into table1 values('č');
select * from table1;
update table1 set col_b = replace(col_b,'č','c');
select * from table1;
How do you have the column defined?