Guys, I have a MySQL db table with an entire column of names, and unfortunately, they are all capitalized. I'm wondering if there is a query I could run to alter the contents of that column, converting every character after the first to lowercase. Example, Current Entry MICHIGAN Converted Entry Michigan Thanks in advance.
Unfortunately, I'm getting an error. select concat(upper(substr(name,1,1)), lower(substr(name,2,length(name)))) from namestable Code (markup):
That command is available from 4.1+ (substr is defined from 4.1.1), so only choice is to use PHP or mysql 4.1+ Anyway, Mysql 4.0.X will be discontinued.
I've got the above query working on the db, using an install of WAMP. I feel so stupid asking this, but what would an update query for the above select query look like? Thanks in advance. Rep forthcoming for answers.
Wait, you want to actually change the value? Or want to output it differently? If it's the former, just run it from a PHP script: $selectquery=mysql_query("SELECT * from sometable"); while($doupdate = mysql_fetch_array($selectquery)) { $newentry = ucfirst(strtolower($doupdate[entry])); mysql_query("UPDATE sometable set entry='$newentry' where id='$doupdate[id]'"); } PHP: Hope that helps.
Yes, I actually want to change the values. I tried via PHP and it yields no result unfortunately. Thanks just the same.
Well, I hope you didn't just paste the code exactly! The script I posted will work considering you've established a connection with the DB, and you've changed my values to suit yours.
And you also changed the table values? It works, I just tried it. There's no reason why it shouldn't.
No, sorry I didn't. I'm slowly learning PHP and MySQL. I think this is easier if I just use a function like ucfirst() in the display code.