Jump to content

Updating usernames


csteff24

Recommended Posts

I have a database of clubs, and each of them has an advisor

As an easy way to add users to the members database, I was thinking I could use mysql to find the first letter of each advisor name, and then the last name (everything after the space) and combine them to create the username to be saved on the members database. Also, I would like the club ID from the club database to be saved to the "club" field of the members database.

 

Any suggestions??

 

Thank you!

 

Link to comment
Share on other sites

This might be what your looking for:

 

INSERT INTO members (username, club) SELECT concat(upper(left(firstname, 1)), '. ', upper(substr(lastname, 0, 1)), substr(lastname, 1)), club_id FROM users

 

One problem though:

upper(substr(lastname, 0, 1)), substr(lastname, 1)

 

This might be able to be simpler but I don't know a function that does something like ucfirst()

Link to comment
Share on other sites

Thank you! The only problem is my advisors field is first and last names, they're not seperated :/

Is there a way to change all of the spaces into underscores? I think I'll just do full name user names

 

ex: advisor: Dan Smith --> username: dan_smith

 

I have no idea if this is the correct, but this is what I have so far...

 

INSERT INTO members2 (username, club) SELECT strtolower(str_replace(" ","_", advisor)), id FROM clubs

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.