0

I have created 4 nodes by a content type called insert_item using CCK; now I am trying to load all CCK fields into a template of a new node where I would use the CCK field value of the insert_item content type.

What I have written is the following code:

$nodes = array();
$result = db_query("SELECT nid FROM {node} WHERE type = 'insert_item'");
while ($row = db_fetch_object($result)) {
  $nodes[] = node_load($row->nid);
  print $nodes;
}

What I got is the following:

ArrayArrayArrayArray

I really don't know what to do.

1

Try changing print $nodes to print_r($nodes) and also move it to the outside of your while loop.

Your code should look like this:

$nodes = array();
$result = db_query("SELECT nid FROM {node} WHERE type = 'insert_item'");
while ($row = db_fetch_object($result)) {
  $nodes[] = node_load($row->nid);
}
print_r($nodes);
//If you use Devel, uncomment this next line and comment out print_r above
//dpm($nodes);

This will give you an easy to read value.

Another option is to use the Devel module, and instead of using print_r you can use dpm() which uses Krumo to pretty print the contents of your array. There are some basic instructions for that dpm() here and here.

Information on print_r here.

If given an array, values will be presented in a format that shows keys and elements. Similar notation is used for objects.

  • Ok thanks now it works:-D , i'd like to print for example all fields called fields_email: [field_email] => Array ( [0] => Array ( [value] => 546546546546@4532132.com ) ) i've thought to print in this way print $field_email[0]['value']; but it dosn't work – Luca Mar 21 '12 at 12:34
  • I think you'll be looking at doing $nodes[0]->field_email[0]['value'] or somesuch. – Chapabu Mar 21 '12 at 13:19
  • yes and it works great! – Luca Mar 21 '12 at 15:43
  • Awesome - glad to be of help. – Chapabu Mar 21 '12 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.