kaninabu
kaninabu

Reputation: 94

capitalizing the first letter of a name in a mySQL table using phpMyadmin

I have a table called users, with a field full_name.

most of the entries have names such as : JOhn perry, lee adams, MONICA Brown. Is there a function in phpmyadmin to standardize these names into a proper format like : John Perry, Lee Adams, Monica Brown? It's for an experimental forum. :)

Upvotes: 0

Views: 2101

Answers (2)

Steph Rose
Steph Rose

Reputation: 2136

First off, I recommend separating the first and last name into separate columns. (first_name and last_name)

If that's the case, then the solution is much easier. You can update the field in mysql using this sql query:

UPDATE users SET full_name = CONCAT(UCASE(SUBSTRING(full_name, 1, 1)),LCASE(SUBSTRING(full_name, 2)));

However, this will make the result be:

MONICA Brown ---> Monica brown DOnald Doe ---> Donald doe

In order to capitalize the first letter of each word, you will need to create a mysql function.

Here's a site with an function you can probably use: http://www.thingy-ma-jig.co.uk/blog/30-09-2010/mysql-how-upper-case-words

Upvotes: 0

ajreal
ajreal

Reputation: 47321

You can always use PHP to do

ucfirst(strtolower($row["full_name"]))

then update the nicely formatted string back to database

Or just simply use the above in your forum script

Upvotes: 1

Related Questions