I have table like this id|type 1|math,science 2|math,science,math 3|science,science 4|math 5|science 6|programming,math,math 7|programming i want to remove duplicated to will be like this id|type 1|math,science 2|math,science 3|science 4|math 5|science 6|programming,math 7|programming i tried to use array_unique but i can't update table???!
build an array and check before adding to the array if the 'key' is already exist.. or 'overwrite' it... and programming,math is harder, have no idea about that.
If those are the only values you need to change, just do it from a mysql console (phpmyadmin or similar) and just do "update table set type = 'science' where type = 'science, science'"
Something like this would do the job: function unique($string) { return implode(',', array_keys(array_flip(explode(',', $string)))); } PHP: Usage : $values = "programming,math,math"; //Output : programming,math echo unique($values); PHP:
Why can't you? If you don't have UPDATE permissions on your MySQL user, then even stored procedure won't help you here. array_unique should work perfectly, maybe if you show us your code we can let you know if there is a mistake in it.
just tested the code from Code Developer, and it seems to be what you want. you just need to code couple of lines.