For sake of simplicity (to as my question), say i have two nodes:

NODE A:
type: "nodea"
field_foo, of type string
NODE B:
type "nodeb"
field_bar, of type integer
field_parent, of type node reference, referencing an instance of Node A

… so a single Node A has many Node Bs associated with it (think "One Pet Store (A) with many Pets (B)" if it helps)

I created my View to join these, and created a relationship for that view linking "B.field_parent" with "A.nid" … it works as expected.

I also added a Parameter, which is a node ID of an instance of A … so i can view one set of joined data … this also works as expected.

And i can go to my site and see each Pet Store:
www.mysite.com/node/42/petstore

Here's my question:

The $row data i get back looks like so:

Row1: nodeA.nid, nodeA.field_foo, nodeB.bar, nodeB_parent
Row2: nodeA.nid, nodeA.field_foo, nodeB.bar, nodeB_parent
Row3: nodeA.nid, nodeA.field_foo, nodeB.bar, nodeB_parent
Row4: nodeA.nid, nodeA.field_foo, nodeB.bar, nodeB_parent
(etc)

meaning, i'm getting back multiple copies of the "NodeA" data for each instance of "NodeB".

my presentation layer, which i'm using Views Templates for (to add Javascript), needs to present the data like so:

NODE A : this is the parent's data
NODE B [0] : This is the 1st child's data
NODE B [1] : This is the 2nd child's data
NODE B [2] : This is the 3rd child's data
NODE B [3] : This is the 4th child's data
(etc)

however, in the tempting, it's not clear how i know i'm in row number 0, therefore i should (a) display the Node A fields and also the Node B fields and then (b) for the remainder of the rows, don't show the Node A fields … just show the Node B fields.

does that make sense?

I just want to display Node A's data once -- and yet it's in every $row… so i need some $row_number (or similar) to know where i am in the overall dataset when i'm generating output in templates like:

views-view--fields-PetStore
and
views-view--field-PetStore
and
views-view--PetStore

(longest question ever)

Comments

nevets’s picture

If your view has a row style output template you could override that.

That template is responsible for output each row and $view->row_index keeps track of the row (starts at zero). That would allow you to selectively print fields.

tlaramee’s picture

i found a way to determine my row ... i'm wondering how it rates on the "hackiness scale" .. any thoughts?:

// $Id: views-view-field.tpl.php,v 1.1 2008/05/16 22:22:32 merlinofchaos Exp $
 /**
  * This template is used to print a single field in a view. It is not
  * actually used in default Views, as this is registered as a theme
  * function which has better performance. For single overrides, the
  * template is perfectly okay.
  *
  * Variables available:
  * - $view: The view object
  * - $field: The field handler object that can process the input
  * - $row: The raw SQL result that can be used
  * - $output: The processed output that will normally be used.
  */
?>
<?php 

$myRowIdx = -1;

// Look through the views total result set for our row (passed as param $row)... 
foreach( $view->result as $idx => $r ) {
  if ( $r == $row ) {
    $myRowIdx = $idx;
    break;
  }
}

?>

i'm not sure on that comparator (==), but i do know the object that's $row is the same as the object $r at the proper index ... so this will work, it'll just be looping entirely too much.

i'll check out the "row style output" and see if i can eliminate looking through all of the results... that sounds like the way to go.

thanks!