Community Documentation

Sum all CCK number fields from all nodes

Last updated December 15, 2010. Created by amal850720 on December 15, 2010.
Log in to edit this page.

I maintain an internal website that serves as an accounting back end to a firm. A content type is created that records general journal entries that has debit and credit fields, among others.

From time to time, the firm's accountant want to check how much cash they have received and paid and further grouped in various classes only accountants know what. These values will then be called to create another content type that produce monthly reports. In the near future, there are plans to call the values elsewhere.

The quick way is use this module and make a SQL query to sum the required fields, as follows:

<?php
   $node_field
[0]['value'] = db_result(db_query("
      SELECT SUM(field_general_journal_debit_value)
      FROM content_type_general_journal
   "
));
?>

The display format is left to its default as follows:

<?php
   $display
= $node_field_item['value'];
?>

Drop the PHP script opening and closing tags in the actual computed code text area.

Create the node, name a title and publish it. If any of the values are changed, this node needs to be republished. This can be done using the Rules module ro whatever necessary. The function can also be called by the name provided just below the code field.

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 6.x
Audience
Programmers, Site administrators

Site Building Guide

Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.