Get the titles of the nodes whose node IDs are contained in a field $attr = explode(",", $node-&gt;field_xlnum[0]['value']);


$node-&gt;field_xlnum[0]['value'] contains 20,4,56,987,68,96, where each value is a node ID.
I want to get all the titles, and output them in an HTML list. How do I do it?

I tried the following code, but it doesn't work.

$attr = explode(",", $node-&gt;field_xlnum[0]['value']);
$result = db_query("SELECT nid, title FROM {node} WHERE nid IN ($attr) AND type = %s order by created DESC", test);
while(($items = db_fetch_object($result)) { 
  $output = theme_item_list($items, array('class'=&gt;'tabs primary'));
}

echo $output;
A few remarks:


You said that $node-&gt;field_xlnum[0]['value'] contains a list of nid separated by comas so you don't need to explode it in order to use them in a IN clause. If you do so, $attr will be an Array().
You put test as an argument in your query, isn't this a variable $test or a string 'test'
You should better use db_placeholders for putting multiples values inside a IN.

$attr = explode(",", $node-&gt;field_xlnum[0]['value']);
db_query("SELECT n.nid, n.title
  FROM {node} n
  WHERE n.nid IN (" . db_placeholders($attr, 'int') . ")
  AND type = %s 
  ORDER BY n.created DESC", $data, 'test'
);