Reference - Data handling - sum


App: manual - Page: fragments/grouping_1
PHP
HTML
fragments/grouping_1.pad
Result
{data 'orders'}
[ {"customer":"Ann","number":101,"total":40}, {"customer":"Bob","number":102,"total":15},
{"customer":"Ann","number":103,"total":25}, {"customer":"Cleo","number":104,"total":60},
{"customer":"Bob","number":105,"total":35} ]
{/data}

{orders group='customer', sum='total'}
<h4>{$customer}: {$count} orders, {$total}</h4>
{rows}
<p>Order {$number}: {$total}</p>
{/rows}
{/orders}


App: manual - Page: fragments/grouping_2
PHP
HTML
fragments/grouping_2.pad
Result
{data 'orders'}
[ {"customer":"Ann","number":101,"total":40}, {"customer":"Bob","number":102,"total":15},
{"customer":"Ann","number":103,"total":25}, {"customer":"Cleo","number":104,"total":60},
{"customer":"Bob","number":105,"total":35} ]
{/data}

<table>
<tr><th>Customer</th><th>Orders</th><th>Total</th><th>Average</th><th>Smallest</th><th>Largest</th></tr>
{orders group='customer', sum='total', avg='total', min='total', max='total', sort='total DESC'}
<tr>
<td>{$customer}</td><td>{$count}</td><td>{$total}</td>
<td>{$avg_total}</td><td>{$min_total}</td><td>{$max_total}</td>
</tr>
{/orders}
</table>


App: regression/framework - Page: options/a_group_aggregate_named_rows_or_count_keeps_the_groups_own
PHP
HTML
options/a_group_aggregate_named_rows_or_count_keeps_the_groups_own.pad
Result
{data 'xs'}[{"t":"a","rows":5,"count":2,"n":1},{"t":"a","rows":7,"count":3,"n":2},{"t":"b","rows":1,"count":1,"n":3}]{/data}
[{xs group='t', sum='rows, count'}{$t}:{$count}:{$sum_rows}:{$sum_count}:{rows}{$n}{/rows}|{/xs}]


App: regression/framework - Page: options/group_offers_avg_min_and_max_under_their_own_names
PHP
options/group_offers_avg_min_and_max_under_their_own_names.php
HTML
options/group_offers_avg_min_and_max_under_their_own_names.pad
Result
<?php

$orders
= [
[
"number" => 1, "customer" => "bob", "total" => "10.10" ],
[
"number" => 2, "customer" => "alice", "total" => 20 ],
[
"number" => 3, "customer" => "bob", "total" => "20.20" ],
[
"number" => 4, "customer" => "alice", "total" => 7 ],
[
"number" => 5, "customer" => "carol", "total" => 1 ]
];

?>
{orders group='customer', avg='total', sum='total', min='total', max='total, number'}[{$customer} {$total} {$sum_total} {$avg_total} {$min_total} {$max_total} {$number}]{/orders}


App: regression/framework - Page: options/group_runs_in_order_with_sort_and_first
PHP
options/group_runs_in_order_with_sort_and_first.php
HTML
options/group_runs_in_order_with_sort_and_first.pad
Result
<?php

$orders
= [
[
"number" => 1, "customer" => "bob", "total" => "10.10" ],
[
"number" => 2, "customer" => "alice", "total" => 20 ],
[
"number" => 3, "customer" => "bob", "total" => "20.20" ],
[
"number" => 4, "customer" => "alice", "total" => 7 ],
[
"number" => 5, "customer" => "carol", "total" => 1 ]
];

?>
{orders sort='total', group='customer'}[{$customer}:{rows}{$number}{/rows}]{/orders}|{orders group='customer', sum='total', sort='total DESC', first=2}[{$customer} {$total}]{/orders}|{orders group='customer', where='$count gt 1', negative}{$customer}{/orders}


App: regression/framework - Page: options/group_sum_keeps_the_decimals_of_a_small_float
PHP
options/group_sum_keeps_the_decimals_of_a_small_float.php
HTML
options/group_sum_keeps_the_decimals_of_a_small_float.pad
Result
<?php

// A float below 0.0001 is written in E notation, 1.0E-5, so its decimals were never
// counted and the sum was rounded to the one decimal of 0.5.

$tiny = [ [ 'g' => 'a', 'x' => 0.00001 ], [ 'g' => 'a', 'x' => 0.5 ] ];

?>
{tiny group="g", sum="x"}{$x}{/tiny}


App: regression/framework - Page: options/group_sums_a_field_and_rows_give_the_row_its_own_value_again
PHP
options/group_sums_a_field_and_rows_give_the_row_its_own_value_again.php
HTML
options/group_sums_a_field_and_rows_give_the_row_its_own_value_again.pad
Result
<?php

$orders
= [
[
"number" => 1, "customer" => "bob", "total" => "10.10" ],
[
"number" => 2, "customer" => "alice", "total" => 20 ],
[
"number" => 3, "customer" => "bob", "total" => "20.20" ],
[
"number" => 4, "customer" => "alice", "total" => 7 ],
[
"number" => 5, "customer" => "carol", "total" => 1 ]
];

?>
{orders group='customer', sum='total'}[{$customer} {$total}:{rows} {$total}{/rows}]{/orders}


App: regression/framework - Page: options/two_sorts_each_sort_on_their_own_value
PHP
options/two_sorts_each_sort_on_their_own_value.php
HTML
options/two_sorts_each_sort_on_their_own_value.pad
Result
<?php

// A sort before first= and one after it, a sort before a group and one after it: each
// sorts on its own value - both sorted on the last one written.

$xs = [ [ 'n' => 3 ], [ 'n' => 1 ], [ 'n' => 2 ], [ 'n' => 5 ], [ 'n' => 4 ] ];
$orders = [ [ 'c' => 'a', 't' => 1, 'd' => '2026-03' ], [ 'c' => 'b', 't' => 9, 'd' => '2026-01' ], [ 'c' => 'a', 't' => 5, 'd' => '2026-02' ],
[
'c' => 'a', 't' => 2, 'd' => '2026-01' ], [ 'c' => 'b', 't' => 1, 'd' => '2026-02' ] ];

?>
[{xs sort='n', first=2, sort='n DESC'}{$n}{/xs}] {orders sort='d', group='c', sum='t', sort='t DESC'}[{$c}:{$t}:{rows}{$d}/{$t},{/rows}]{/orders}