Hi,

I am quite confused on how do I solve below problem -

I have some nodes bookmarked by a user of type A. Those nodes are being referred by another set of nodes of type B. I need to display the titles of the set of nodes of type B referring all the nodes of type A bookmarked bye a particular user when he/she logged-in (in a block).

Please help. I don't know how to achieve this.

Regards and lots of thanks!

Neotechie

Comments

derjochenmeyer’s picture

i dont think there is a way with core modules or views. For sure it can be done with a custom query including some JOIN statements. If nobody has a better idea i could try to point out a direction.

What modules are you using for the bookmarking?

----------------------
okay.cool

neotechie’s picture

Hi,
Thank you very much for your reply.

I am using Views Bookmark http://drupal.org/project/views_bookmark . I am in fact open to use any other bookmark module if needed (click2bookmark). Pleas let me know. Your help is greatly appreciated.

Regards.

derjochenmeyer’s picture

ohh... i never worked with that module... i would have to try it out...

anybody with ideas???

----------------------
okay.cool

neotechie’s picture

I'll wait for your suggestion. No-one seems to be interested in this problem!

Neotechie

derjochenmeyer’s picture

i guess there will be a lot of room for improvement, but this worked in a fast test i did. I quickly installed the module and made some references between some node types. You just stick that code in a new block with PHP Filter enabled.

I tested like this.

bookmarked node1 -----referenceTo-----> mainnode1
bookmarked node2 -----referenceTo-----> mainnode2

THIS ONLY WORKS IF YOUR REFERENCE FIELD IS ONLY USED IN ONE NODETYPE. If you reuse the field it doesnt get stored in the content_type_YOURTYPE table, but in its own.

ALSO NOTICE that you have to rename field_reference_nid TO field_YourFieldname_nid (you can look that up in the database if your not sure)

<?php
// gets the current user object because we need the uid ($user->uid)
global $user;

// query the views_bookmark_nodes table and get all the node id of bookmarked nodes
$nid_array = db_query(db_rewrite_sql("SELECT nid FROM {views_bookmark_nodes} WHERE uid = %d", $user->uid), $user->uid);

// prepare output in unordered list
print '<ul>';

// now we need to get the referred node for each bookmark
while ($nid = db_fetch_object($nid_array)) {

  // since we maybe have to query different node type, lets get the current node type first
  $node_type = db_result(db_query("SELECT type FROM {node} WHERE nid = $nid->nid"));

  // query the content_type_YOURTYPE table 
  $reference_nid = db_result(db_query("SELECT field_reference_nid FROM {content_type_$node_type} WHERE nid = $nid->nid"));

  // get the title of the node
  $reference_title = db_result(db_query("SELECT title FROM {node} WHERE nid = $reference_nid"));

  // print the link
  print '<li><a href="/node/'. $reference_nid .'">'. $reference_title.'</a></li>';
}

// close unordered list
print '</ul>';
?>

the problem is, its hard to make a gereric approach. There are many small details that may require a totally different approach. Hope this helps.

----------------------
okay.cool

neotechie’s picture

A big thanks Jochen Meyer!!

I will test this and come back. But I think I did not explain the problem correctly. What I am trying to do is below -

node1 -----referenceTo-----> bookmarked mainnode1
node2 -----referenceTo-----> bookmarked mainnode2

Displaying node1 & node2 and others which are referencing mainnodes.

As now you have directed me I will try and see I I can use your code and solve the problem.

Thanks Again!

neotechie’s picture

Hi,
While using the above code I get the below error. I am not sure why. Please help.

user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'nid), FROM views_bookmark_nodes WHERE uid = 1' at line 1 query: SELECT DISTINCT(1.nid), FROM views_bookmark_nodes WHERE uid = 1 in C:\wamp\www\drupal-5.2V2\includes\database.mysql.inc on line 172.

Thanks,
Piyush

derjochenmeyer’s picture

no clue... the bookmark views module is installed?

----------------------
okay.cool

neotechie’s picture

yes it is installed.

jakosa’s picture

I have had a similar kind of problem. Made this post and haven't got any replies.

It seems that Drupal have some problems when it comes to organizing content in relative databases. The node-reference field in CCK only refers to the Title.

I have tried a little with Views fusion (requires -Node Family-) I think it might solve your problem.

Not mine unfortunately.

lelizondo’s picture

I have a similar problem, the node-reference field in cck only refers to the title, in my case, i need a reference to a date so I can filter using a view. made a post but no reply.

if you find a solution to the node-reference not refering to the title please post link here..

Luis

Luis