I am trying to get some additional information into a Views list by executing an sql query. The problem is that I need the uid of the views node, but this information doesn't seem to be held in the $node of the view.

However, as $node->nid is valid for each node returned by the view, I can use this to get the uid. My problem is that I can't get the sql that would allow me to get the title of another node by the same uid. I suppose I could do it with two seperate sql queries (one to get the uid from the first node and the other to get the title of the second node based on the uid).

Can someone give me a clue on whether/how I might do this via a single query?

with $node->nid I can get the uid, using that uid I can then get a title from another node.

Hope someone with some better SQL knowledge can help.

Thanks

Comments

emzi’s picture

1. 'Views list' - is it a list of views or a list of nodes generated by some view
2. What is a 'views node'
3. How are you going to determine 'another node' if you get them by uid? There may be a lot of nodes with the same uid (even entire site)

/Michael

gmak’s picture

1. When I say 'views list' I mean list of nodes generated by a view.
2. A 'views node' is one of the nodes listed by the view.
3. I will get the other node by uid & type. Since this is a nodeprofile, there will only be one per uid.

Essentially, my View will return a list of 'publications'. When displaying this list, I'd like to include the full name of the author which is the 'title' of their nodeprofile.

thanks,
G

emzi’s picture

if you use phptemplate to theme your view, you can call user_load function: $tempuser=user_load(array('uid'=>$node->uid)); and then insert $tempuser object fields where you need
/Michael

jubjub77’s picture

if you use phptemplate to theme your view, put that in you view-name_of_view.tpl.php :

<?php
global $user;
if ( arg(0) == 'node' && is_numeric(arg(1)) && ! arg(2) ) {
$node = node_load(arg(1)); }
$author = user_load(array('uid'=>$node->uid));
profile_load_profile($author);

print $author->uid;
?>