I'm trying to create a view that displays fields from both a node and the profile of the user that references that node. I have a "project" node type with a user reference pointing the the "leader". I want to build a list view that looks something like this:

Project Name | Leader Name | Leader Organization | Leader E-mail

The project name comes from the "project" node while the other fields are in the user profile. I can easily build a view around the "project" node that includes the project name and the leader name (which is a user reference), but I can't figure out how to pull in any other fields from that user's profile.

Another approach would be to build a view around the user, but if I do that, there doesn't seem to be any way to pull in the title of the project referenced by that user. The user's profile contains links to the projects that reference the user, but views doesn't seem to provide access in this way.

Any ideas? Thanks!

Comments

johnichiban’s picture

Title: Building a view containing fields from a node and a user profile that references that node? » Data fields from referenced user?
merlinofchaos’s picture

Views 1 can't do this.

johnichiban’s picture

Hrm, if views 1 doesn't do this, it sounds like my best bet would be to create a node with a custom query embedded in it? It sounds feasible, but I've not written a SQL query in about 6 years. I guess I need a query that grabs the project name and the UID of the related user from the "node" and "content_type_project" tables and then grabs the relevant user information using that UID from the "user" and "profile" tables. If these results are pulled into an array, it should be fairly easy to iterate through and build a table to display the results. Anyone have any pointers on the SQL query and code to build that array?

Something like this gets me pretty close, but when I try to pull in the profile fields, it occurred to me that a join might be required, and I'm not sure of the proper syntax:


$result = db_query_range('SELECT award.field_relatedusers_uid, award.field_pi_value, user.name, user.uid, user.mail FROM {content_type_award} award, {users} user WHERE award.field_relatedusers_uid > 0 AND user.uid = award.field_relatedusers_uid', $uid, 0, 10);

while ($node = db_fetch_object($result)) {
   print_r($node);
  }

Any idea how I can add fields from the profile table to this query?

Thanks!

daneyuleb’s picture

>>> Views 1 can't do this.

Are you saying that Views 2 -does- do this? What are the steps?

I'm building a node view, but need to pull in the Location fields from the User profile...can this be done in Views 2? If so, what are the general steps?

daneyuleb’s picture

Never mind. I see now that the Relationships feature is the way to do it in Views 2....very, very nice!

domesticat’s picture

Closed while closing all Views support requests with no activity for 6 months. If you still need help, you may re-open this issue at any time.

hellomobe’s picture

daneyuleb, can you explain how you set up the views relationship.

1. I made a relationship with the cck field that has the user_reference.
2. Then I have the fields (name, phone, etc) I want to show under the fields area.

Unfortunately I get the logged in user, not the profile values for the user referenced. Not sure if I need an argument or where to go from here. FYI - My cck user-reference field can have multiple users referenced.

On the display of the node, I would like it to show the name and phone of the user referenced rather than the user-reference link.

Second question, were you able to get this in the $content of the custom node-content_type.tpl - if so how, or how did you display the view results?

merlinofchaos’s picture

Status: Active » Closed (fixed)

Whoops. domesticat commented closing this issue, then did not actually close it.

domesticat’s picture

Bad kitty. No cookie.