[SOLVED] "Single" name to "First and Last" name

13 years 8 months ago #138921 by noerkjaer
Hope someone can help me.

I manage a site for our rowingclub with approx 250 members. We have nothing fancy 3rd party BD-addons installed.

So far we've used the "Single name" set-up via Joomla's core "User management".

In CB all names are shown as wel using the "Single name" setting. But if I change to the "First and Last name" in CB all name-fields goes blank.

I know they go blank because the fields are empty in the CB-profile. But my question is how to get the "single name" from Joomla split in to the CD database with firat and last name?

Do I have to edit 250 members manually, or is there some sort of automatic process that can do most of the hard work for me?

A great help would be if first word in the Joomla-single-name was put in to the "CB First name" and the rest into "CB last name"

Regards Peter

Post edited by: krileon, at: 2010/08/11 18:05

Please Log in to join the conversation.

13 years 8 months ago #138965 by krileon
Once you've changed the name format please try running CB tools as it may be capable of fixing it. If not users will need to re-save their profiles or you can manually fix the users within CBs User Management. You could also try running a database query to perform the change for you. An example query as follows. Please note the query may not work to your liking. Always perform a database backup before performing direct queries.

[code:1]
UPDATE `jos_comprofiler` AS cb
LEFT JOIN `jos_users` AS j
ON j.`id` = cb.`user_id`
SET
cb.`firstname` = SUBSTRING_INDEX( j.`name`, ' ', 1 ),
cb.`lastname` = SUBSTRING_INDEX( j.`name`, ' ', -1 )
[/code:1]


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

13 years 8 months ago #139067 by noerkjaer
Replied by noerkjaer on topic Re:From "Single name" to "First and
Splendid!!! :woohoo:

You just saved me three evenings of manual work! Thanks a million! B)

I'm not that much in to SQL queries, so perhaps you can help me with a small detail. With your script first and last names are saved, but middle names are lost.

Is there a way to make everything except the first name to be set as last name?
So "Barack Hussein Obama" would be [First: Barack] and [Last: Hussein Obama].

Or if I change the CB-setting to "First, middle and last" can the script pu everything but the first and last name (if there are any) as middle name?

No matter what can be done - thanks! It woked like a charm, and saved me quite many hours.

Post edited by: noerkjaer, at: 2010/07/30 20:09

Please Log in to join the conversation.

13 years 8 months ago #139335 by krileon
Replied by krileon on topic Re:From "Single name" to "First and
Well have spent too much time on a non-issue, but with a few spare moments of personal time have thrown together the query for you. The following show format first, middle, and last name correctly from the Name field in the _users table. Please be sure to backup your database!

[code:1]
UPDATE `jos_comprofiler` AS cb
LEFT JOIN `jos_users` AS j
ON j.`id` = cb.`user_id`
SET
cb.`firstname` = TRIM( SUBSTRING_INDEX( j.`name`, ' ', 1 ) ),
cb.`middlename` = TRIM( REPLACE( REPLACE( j.`name`, SUBSTRING_INDEX( j.`name`, ' ', 1 ), '' ), SUBSTRING_INDEX( j.`name`, ' ', -1 ), '' ) ),
cb.`lastname` = TRIM( SUBSTRING_INDEX( j.`name`, ' ', -1 ) )
[/code:1]

To test if the above will properly display, please run the below test query. The below query is just a select so no damage can come of it and will give you a preview of the above queries results.

[code:1]
SELECT
TRIM( SUBSTRING_INDEX( `name`, ' ', 1 ) ) AS 'first_name',
TRIM( REPLACE( REPLACE( `name`, SUBSTRING_INDEX( `name`, ' ', 1 ), '' ), SUBSTRING_INDEX( `name`, ' ', -1 ), '' ) ) AS 'middle_name',
TRIM( SUBSTRING_INDEX( `name`, ' ', -1 ) ) AS 'last_name'
FROM `jos_users`
[/code:1]


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

13 years 8 months ago #139675 by noerkjaer
Replied by noerkjaer on topic Re:From "Single name" to "First and
WOW! :woohoo:

Thanks! I really owe you one!

Worked like a charm, and I only had to edit a few users that have two first names.

You really are my hero of the day! :side:

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.196 seconds

Facebook Twitter LinkedIn