We need some groups now!

Lets suppose you need some grouping by the city. And need a row with the field description, that the city name just appears on the group header and sum all the values of that city on the group footer. It's easy, let's see sales4.xml:
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<!DOCTYPE REPORT SYSTEM "PHPReport.dtd">
<REPORT>
   <TITLE>Sales Report</TITLE>
   <BACKGROUND_COLOR>#FFFFFF</BACKGROUND_COLOR>
   <CSS>phpreports.css</CSS>
   <PAGE BORDER="1" SIZE="25" CELLSPACING="0" CELLPADDING="5" WIDTH="500">
      <HEADER>
         <ROW>
            <COL COLSPAN="4" CELLCLASS="PAGE_LAYER" TEXTCLASS="BOLD">John Doe Enterprises</COL>
         </ROW>
         <ROW>
            <COL COLSPAN="4" CELLCLASS="PAGE_LAYER" TEXTCLASS="BOLD">Sales Report</COL>
         </ROW>
      </HEADER>		
      <FOOTER>
         <ROW>
            <COL ALIGN="RIGHT" COLSPAN="3" CELLCLASS="PAGE_LAYER">page total</COL>
            <COL ALIGN="LEFT" NUMBERFORMATEX="2" CELLCLASS="PAGE_LAYER" TEXTCLASS="BOLD" TYPE="EXPRESSION">$this->getSum("value")</COL>
         </ROW>
      </FOOTER>		
   </PAGE>
   <GROUPS>
      <GROUP NAME="citygroup" EXPRESSION="city">
         <HEADER>
            <ROW>
               <COL CELLCLASS="GROUP_LAYER">city:</COL>
               <COL CELLCLASS="GROUP_LAYER" TEXTCLASS="BOLD" TYPE="EXPRESSION" COLSPAN="3">$header->getValue("city")</COL>
            </ROW>
            <ROW>
               <COL CELLCLASS="GROUP_LAYER">id</COL>
               <COL CELLCLASS="GROUP_LAYER">name</COL>
               <COL CELLCLASS="GROUP_LAYER">product</COL>
               <COL CELLCLASS="GROUP_LAYER">$</COL>
            </ROW>
         </HEADER>
         <FOOTER>
            <ROW>
               <COL ALIGN="RIGHT" COLSPAN="3" CELLCLASS="GROUP_LAYER">total</COL>
               <COL ALIGN="LEFT" CELLCLASS="GROUP_LAYER" TEXTCLASS="BOLD" NUMBERFORMATEX="2" TYPE="EXPRESSION">$this->getSum("value")</COL>
            </ROW>
         </FOOTER>
         <FIELDS>
            <ROW>
               <COL TYPE="FIELD" CELLCLASS="GROUP_LAYER">id</COL>
               <COL TYPE="FIELD" CELLCLASS="GROUP_LAYER">name</COL>
               <COL TYPE="FIELD" CELLCLASS="GROUP_LAYER">product</COL>
               <COL TYPE="FIELD" CELLCLASS="GROUP_LAYER" NUMBERFORMATEX="2">value</COL>
            </ROW>
         </FIELDS>
      </GROUP>
   </GROUPS>
</REPORT>
And now it looks like this:

sales.xml result file

Now we're talking! :-) Our first group put all the information regarding the field city on one block and created a header and a footer to it, with the value field total on it. Please noticed that I changed the group name (<GROUP NAME="citygroup">) and used a expression to make it breaks when it change (mandatory in groups that breaks - <GROUP NAME="citygroup" EXPRESSION="city">).
The expression you use on the group element attribute is one of the report fields. When it changes, automatically the group will print its footer (if have one). There you can use some of the grouping functions to get your results. The $this-> reference there will point just for the current group.
Notice also that I used an attribute NUMBERFORMATEX="2" to round the field values to two decimal places.
"Ok, now I want to make a sub-group, for each customer inside each city" ... no problem!
Here is the sales5.xml:
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<!DOCTYPE REPORT SYSTEM "PHPReport.dtd">
<REPORT>
   <TITLE>Sales Report</TITLE>
   <BACKGROUND_COLOR>#FFFFFF</BACKGROUND_COLOR>
   <CSS>phpreports.css</CSS>
   <PAGE BORDER="1" SIZE="25" CELLSPACING="0" CELLPADDING="5" WIDTH="500">
      <HEADER>
         <ROW>
            <COL COLSPAN="4" CELLCLASS="PAGE_LAYER" TEXTCLASS="BOLD">John Doe Enterprises</COL>
         </ROW>
         <ROW>
            <COL COLSPAN="4" CELLCLASS="PAGE_LAYER" TEXTCLASS="BOLD">Sales Report</COL>
         </ROW>
      </HEADER>		
      <FOOTER>
         <ROW>
            <COL ALIGN="RIGHT" COLSPAN="3" CELLCLASS="PAGE_LAYER">page total</COL>
            <COL ALIGN="LEFT" NUMBERFORMATEX="2" CELLCLASS="PAGE_LAYER" TEXTCLASS="BOLD" TYPE="EXPRESSION">$this->getSum("value")</COL>
         </ROW>
      </FOOTER>		
   </PAGE>
   <GROUPS>
      <GROUP NAME="citygroup" EXPRESSION="city">
         <HEADER>
            <ROW>
               <COL CELLCLASS="GROUP_LAYER">city:</COL>
               <COL CELLCLASS="GROUP_LAYER" TEXTCLASS="BOLD" TYPE="EXPRESSION" COLSPAN="3">$header->getValue("city")</COL>
            </ROW>
            <ROW>
               <COL CELLCLASS="GROUP_LAYER">id</COL>
               <COL CELLCLASS="GROUP_LAYER">name</COL>
               <COL CELLCLASS="GROUP_LAYER">product</COL>
               <COL CELLCLASS="GROUP_LAYER">$</COL>
            </ROW>
         </HEADER>
         <FOOTER>
            <ROW>
               <COL ALIGN="RIGHT" COLSPAN="3" CELLCLASS="GROUP_LAYER">city total</COL>
               <COL ALIGN="LEFT" CELLCLASS="GROUP_LAYER" TEXTCLASS="BOLD" NUMBERFORMATEX="2" TYPE="EXPRESSION">$this->getSum("value")</COL>
            </ROW>
         </FOOTER>
         <GROUP NAME="customergroup" EXPRESSION="name">
            <FOOTER>
               <ROW>
                  <COL ALIGN="RIGHT" COLSPAN="3" CELLCLASS="GROUP_LAYER">customer total</COL>
                  <COL ALIGN="LEFT" CELLCLASS="GROUP_LAYER" TEXTCLASS="BOLD" NUMBERFORMATEX="2" TYPE="EXPRESSION">$this->getSum("value")</COL>
               </ROW>
            </FOOTER>
            <FIELDS>
               <ROW>
                  <COL TYPE="FIELD" CELLCLASS="GROUP_LAYER">id</COL>
                  <COL TYPE="FIELD" CELLCLASS="GROUP_LAYER">name</COL>
                  <COL TYPE="FIELD" CELLCLASS="GROUP_LAYER">product</COL>
                  <COL TYPE="FIELD" CELLCLASS="GROUP_LAYER" NUMBERFORMATEX="2">value</COL>
               </ROW>
            </FIELDS>
         </GROUP>
      </GROUP>
   </GROUPS>
</REPORT>
And now it looks like this:

sales.xml result file

All you need to do is insert a GROUP element inside the other group element. In this case we have two groups, citygroup and customergroup. The citygroup is the main group, the group that have childs but not parent (customergroup is its child) and customergroup is the detail group, the group where the values will appear. Check the DTD file to see how the groups are stored.
So, we're done and ... WAIT!!! Where is the report total???
Oh man, I forgot it ehehe but dont fear, its easy too !!!
Just let me mention that the DOCUMENT HEADER and FOOTER elements are separated from the rest of the page layout, I mean, since it just have the DOCUMENT values after all the pages are processed, its different tables (remember: the full page is a table) after the page table. To make more clear the damage it does: it dont respect the width of the page columns, because it is outside the table columns. So if you really need the DOCUMENT HEADER and FOOTER be aligned with the rest of page, calculate and use the WIDTH attribute on all your COL elements.
So here we go, now its sales6.xml:
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<!DOCTYPE REPORT SYSTEM "PHPReport.dtd">
<REPORT>
   <TITLE>Sales Report</TITLE>
   <BACKGROUND_COLOR>#FFFFFF</BACKGROUND_COLOR>
   <CSS>phpreports.css</CSS>
   <DOCUMENT>
      <FOOTER BORDER="1" CELLSPACING="0" CELLPADDING="5" WIDTH="500">
         <ROW>
            <COL ALIGN="RIGHT" CELLCLASS="DOCUMENT_LAYER" WIDTH="430">report total</COL>
            <COL ALIGN="LEFT" CELLCLASS="DOCUMENT_LAYER" TEXTCLASS="BOLD" NUMBERFORMATEX="2" TYPE="EXPRESSION">$this->getSum("value")</COL>
         </ROW>
      </FOOTER>		
   </DOCUMENT>
   <PAGE BORDER="1" SIZE="25" CELLSPACING="0" CELLPADDING="5" WIDTH="500">
      <HEADER>
         <ROW>
            <COL COLSPAN="4" CELLCLASS="PAGE_LAYER" TEXTCLASS="BOLD">John Doe Enterprises</COL>
         </ROW>
         <ROW>
            <COL COLSPAN="4" CELLCLASS="PAGE_LAYER" TEXTCLASS="BOLD">Sales Report</COL>
         </ROW>
      </HEADER>		
      <FOOTER>
         <ROW>
            <COL ALIGN="RIGHT" COLSPAN="3" CELLCLASS="PAGE_LAYER">page total</COL>
            <COL ALIGN="LEFT" NUMBERFORMATEX="2" CELLCLASS="PAGE_LAYER" TEXTCLASS="BOLD" TYPE="EXPRESSION">$this->getSum("value")</COL>
         </ROW>
      </FOOTER>		
   </PAGE>
   <GROUPS>
      <GROUP NAME="citygroup" EXPRESSION="city">
         <HEADER>
            <ROW>
               <COL CELLCLASS="GROUP_LAYER">city:</COL>
               <COL CELLCLASS="GROUP_LAYER" TEXTCLASS="BOLD" TYPE="EXPRESSION" COLSPAN="3">$header->getValue("city")</COL>
            </ROW>
            <ROW>
               <COL CELLCLASS="GROUP_LAYER">id</COL>
               <COL CELLCLASS="GROUP_LAYER">name</COL>
               <COL CELLCLASS="GROUP_LAYER">product</COL>
               <COL CELLCLASS="GROUP_LAYER">$</COL>
            </ROW>
         </HEADER>
         <FOOTER>
            <ROW>
               <COL ALIGN="RIGHT" COLSPAN="3" CELLCLASS="GROUP_LAYER">city total</COL>
               <COL ALIGN="LEFT" CELLCLASS="GROUP_LAYER" TEXTCLASS="BOLD" NUMBERFORMATEX="2" TYPE="EXPRESSION">$this->getSum("value")</COL>
            </ROW>
         </FOOTER>
         <GROUP NAME="customergroup" EXPRESSION="name">
            <FOOTER>
               <ROW>
                  <COL ALIGN="RIGHT" COLSPAN="3" CELLCLASS="GROUP_LAYER">customer total</COL>
                  <COL ALIGN="LEFT" CELLCLASS="GROUP_LAYER" TEXTCLASS="BOLD" NUMBERFORMATEX="2" TYPE="EXPRESSION">$this->getSum("value")</COL>
               </ROW>
            </FOOTER>
            <FIELDS>
               <ROW>
                  <COL TYPE="FIELD" CELLCLASS="GROUP_LAYER">id</COL>
                  <COL TYPE="FIELD" CELLCLASS="GROUP_LAYER">name</COL>
                  <COL TYPE="FIELD" CELLCLASS="GROUP_LAYER">product</COL>
                  <COL TYPE="FIELD" CELLCLASS="GROUP_LAYER" NUMBERFORMATEX="2">value</COL>
               </ROW>
            </FIELDS>
         </GROUP>
      </GROUP>
   </GROUPS>
</REPORT>
And now it looks like this (again):

sales.xml result file