The group option folds the rows of any data tag into one occurrence per
distinct value of a field. Each group holds that value, $count - the number of
rows in the group - and rows, the group's own rows as nested data. Inside
{rows} a field is the row's own value again.
|
PHP |
HTML fragments/grouping_1.pad |
Result |
|---|---|---|
|
Ann: 2 orders, 65Order 101: 40 Order 103: 25 Bob: 2 orders, 50Order 102: 15 Order 105: 35 Cleo: 1 orders, 60Order 104: 60 |
sum, avg, min and max name the fields to
aggregate over each group's rows. The aggregate is stored under the field's own name -
{$total} above is the sum - and under the aggregate joined to it -
{$sum_total}, {$avg_total} - so one field can be
summed and averaged at once. A field list such as sum='total, quantity'
aggregates each of them.
|
PHP |
HTML fragments/grouping_2.pad |
Result | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
Handling options run in the order they are written. Groups come in the order their first
row appears: a sort written before the group orders the groups and the rows
inside them, a sort written after it orders the groups - also on an aggregate,
as above. first, page and where written after the group
count groups: {orders group='customer', where='$count gt 1'} keeps the
customers with more than one order. Several fields - group='year, month' - group
on the combination, and {rows group='month'} groups again inside a
group.