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 Answer 1

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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