Given a view, named 'Children' (with two fields: child_node_id and a birth_order_value) what is the best way, programmatically, to iterate through the views results set given a display_id of 'default' and an argument that contains the parent node id?
Previously, I have used the View in a block using code similar to the following:
if ( arg(0) == 'node' && is_numeric(arg(1)) && ! arg(2)) {
$node = node_load(arg(1));
$args = array($node->nid);
$view = views_get_view('Children');
print $view->preview('default', $args);
}
However, in another block I want to perform some logic based on the values found in the view. You might be able guess that business logic based on my final requirement: I want the block of code supporting the view ('Children') be called multiple times. As I iterate through the view dataset results, I want to recursively iterate through the children nodes querying for their children.
foreach
instead of for(..sizeof()), it performs a lot better (because it is C instead of PHP).if (arg(0) == 'node' && is_numeric(arg(1)) && ! arg(2))
, it might be better to useif ($node = menu_get_object())
.