How can I access cell data using field_get_items('node',$node, 'table_fieldname')?
I tried as follows without success:
$mytable = field_get_items('node',$node, 'table_fieldname');
$my_cell_1 = $mytable[0]['value'];
print $my_cell_1;
which seems to return the complete array.
How can I extract cell data?

Comments

j4’s picture

Were you able to find a solution?

Thanks
Jaya

spineless’s picture

Use the Devel module to look at the field data for the node. You will see the table elements in the Devel tab of the node.

I was able to collect data from the cells and do a total.

This code does an ROI calculation of a table of data.


if ((arg(0) == 'node') && is_numeric(arg(1)) && !(arg(2))) {
   $node = node_load(arg(1));
   $profit = $node->field__gains[und][0]['value'];
   $cost = $node->field_cost_of_in[und][0]['value'];
   $sumtotal = $profit + $costs;
   $directtext = "/% annualized return";
   $t1 = $node->field_roi_table[und][0][tabledata][3][1];
   $t2 = $node->field_roi_table[und][0][tabledata][3][2];
   $t3 = $node->field_roi_table[und][0][tabledata][3][3];
   $t4 = $node->field_roi_table[und][0][tabledata][3][4];
   $t5 = $node->field_roi_table[und][0][tabledata][3][5];
   $tableprofit = $t1 + $t2 + $t3 + $t4 + $t5;
   $e1 = $node->field_roi_table[und][0][tabledata][2][1];
  $e2 = $node->field_roi_table[und][0][tabledata][2][2];
  $e3 = $node->field_roi_table[und][0][tabledata][2][3];
  $e4 = $node->field_roi_table[und][0][tabledata][2][4];
  $e5 = $node->field_roi_table[und][0][tabledata][2][5];
  $tablei = $e1 + $e2 + $e3 + $e4 + $e5;
  $numerator= $tableprofit - $tablei;
  $demoninator = $tablei * 5;
  $roi = $numerator / $demoninator;
  $roi_percent = $roi * 100;
    print "<strong>$roi_percent %</strong></br>";
}

I put this code inside the body of a different field on the same page and selected PHP CODE as the Text format.

Hope this helps.

sylwester’s picture

Version: 7.x-2.0-beta4 » 7.x-2.2

any luck with writing into cells?

  $node -> field_roi_table[und][0][tabledata][2][5] = 5;

above code will not work.

Thanks,

newtoid’s picture

I need to do a similar thing with a table but there are undefined numbers of rows in each table. the columns remain the same, i just need to do totals on specific columns.

lolandese’s picture

How can I extract cell data?

#2697105: RFC: Proposal to Enable Table Data Storage as JSON would ease this request.

lolandese’s picture

Version: 7.x-2.2 » 7.x-3.x-dev
liam morland’s picture

Status: Active » Fixed

Presuming fixed.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.