Hello,

I was wondering if someone could help with the following request.
I would like two CCK fields to display as one field in Views.

For example, in the profile registration I fill out 'First Name' field and 'Last Name' field.
In the Views, I would like one field that show "First Name(space)Last Name" using custom views field.

I would truly appreciate any help on this.
Thank you very much in advance.

Comments

Bilmar’s picture

Title: Merging two Fields to show as one » Merge two Profile Fields to show as one Field
Category: feature » support

Hello again,
I changed the issue settings to better fit my request.
Is there anyone that can help me with the php coding for the above requirement.
Thank you!

casey’s picture

1. Add the two fields you want to combine to your view.
2. Exclude them from display (optional).
3. Add a "Custom Field: PHP Code".
4. Find out what variable names your two fields have (use print_r($data) in the PHP Code field).
5. Use something like this in your PHP Code field:

echo $data->node_data_field_firstname . ' ' . $data->node_data_field_lastname;
Bilmar’s picture

Thank you very much for your help! I have been studying drupal and php very hard to better understand how to make a website.

Would you happen to know how I could have it "(First Name) [space] (Inital of Last Name)" in the custom field?

casey’s picture

echo $data->node_data_field_firstname . ' ' . $data->node_data_field_lastname[0] . '.';

or

echo $data->node_data_field_firstname . ' ' . substr($data->node_data_field_lastname, 0, 1) . '.';
bmblack’s picture

I'm sorry, I dont understand these steps. Could somebody explain them in more detail please? I'd REALLY appreciate it.

1. I added two new fields (went into my content types -> user profile -> new field). The two fields I added were: field_firstname and field_lastname.

2. By default they don't display anywhere, so that's good.

3. I'm not sure how to add a "Custom Field: PHP Code".

4. Could somebody explain how to do this?

5. I think if I can get help with steps 3-4, this code would work.

I really appreciate any help!!

Thanks in advance.