<?xml version="1.0" encoding="UTF-8"?>    <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
      <channel>
        <title>Total from Generated Column?</title>
        <link>https://interactivetools.com/forum/forum-posts.php?Total-from-Generated-Column-82791</link>
        <description></description>
        <pubDate>Sat, 07 Mar 2026 10:12:15 -0800</pubDate>
        <language>en-us</language>
        <atom:link href="https://interactivetools.com/forum/forum-posts.php?rss=1&amp;Total-from-Generated-Column-82791" rel="self" type="application/rss+xml" />

                <item>
          <title>Total from Generated Column?</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2247138#post2247138</link>
          <description><![CDATA[<p>Hi Mark, </p>
<p>Generated columns is more for when you want to sum up multiple fields within a single row.  Say you had cost and tax and wanted to show them together.</p>
<p>What's it for?  If you want to get a sum of all the fields in a table from all the rows you could do something like this with ZenDB:  </p>
<pre class="language-php"><code>$table   = "products";
$field   = "cost";
$results = DB::query("SELECT SUM($field) FROM :_$table")-&gt;orThrow();
$sum     = $results-&gt;row(0)-&gt;col(0)-&gt;raw();
showme($sum);

// or all in one line
$sum = DB::query("SELECT SUM(cost) FROM :_products")-&gt;orThrow()-&gt;row(0)-&gt;col(0)-&gt;raw();</code></pre>
<p>Here's what the different parts do: </p>
<ul>
<li>DB::query - executes a MySQL query and returns the result</li>
<li>SELECT SUM(cost) FROM :_products - the MySQL query, ":_" gets replaced with the table prefix</li>
<li>-&gt;orThrow() - outputs (throws) an error if there is an error with the sql</li>
<li>-&gt;row(0) gets the first row of the result</li>
<li>-&gt;col(0) gets the first column</li>
<li>-&gt;raw() returns the actual value (not an object)</li>
</ul>
<p>Also, you might want to get your cost column type to DECIMAL in the field editor so you are guaranteed numeric values.</p>
<p>Let me know if that works for you.</p>]]></description>
          <pubDate>Thu, 18 Apr 2024 09:12:54 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2247138#post2247138</guid>
        </item>
                <item>
          <title>Total from Generated Column?</title>
          <link>https://interactivetools.com/forum/forum-posts.php?postNum=2247137#post2247137</link>
          <description><![CDATA[<p>I'm just wondering if I can use the new Generated Column fields to perform a simple totally task.</p>
<p>Essentially, I'm using a multi-record editor and one of my textfields in each record (simply called 'cost') is for the cost of a product, where I put a normal numerical value like 10 or 6.3 etc. But can I use the new Generated Columns field to essentially create a total for all my 'cost' field records? I'm not quite sure how to approach this in CMSB.</p>]]></description>
          <pubDate>Thu, 18 Apr 2024 00:28:22 -0700</pubDate>
          <guid isPermaLink="true">forum-posts.php?postNum=2247137#post2247137</guid>
        </item>
              </channel>
    </rss>
  