我想显示表内每一列的总数。这是我的代码。

$Tab_info['Width'] = "600" ;
$Col_det = array(
    'Name' => array( 'Name',
                    'Aging Create Order ( <= 5 )',
                    'Aging Create Order ( > 5 )',
                    'Total'),
    'Size' => array( '200' ,  '200' ,  '200' ,  '100'  ),
    'Type' => array('sortable-text fd-column-', 'sortable-numeric fd-column-','sortable-numeric fd-column-','sortable-numeric fd-column-'));

$Delim_String = '<table id="Summary" class="sortable-onload-0-normal rowstyle-alt no-arrow" style="width:'.$Tab_info['Width'].'px;background-color:#FFFFFF;">';
$Delim_String .= '<thead><tr>';
                    for ($Col_count = 0; $Col_count < sizeof($Col_det['Name']) ; $Col_count++) {
$Delim_String .= '<th style="-moz-user-select: none;" class="'.$Col_det['Type'][$Col_count].$Col_count.'" width="'.$Col_det['Size'][$Col_count].'">';
$Delim_String .= '<a title="Sort on '.$Col_det['Name'][$Col_count].'" href="#">'.$Col_det['Name'][$Col_count].'</a>';
$Delim_String .= '</th>';
}

$Delim_String .= '</tr>
  </thead>
  <tbody>
    ';
//===================Summary Aging Create Order End===========================

$vSQL = "SELECT u.Nama as Name,
         SUM( CASE WHEN t.`AgingCreateOrder` <= 5 THEN 1 ELSE 0 END) 'Aging Less Than or Equal 5',
         SUM( CASE WHEN t.`AgingCreateOrder` > 5 THEN 1 ELSE 0 END) 'Aging More Than 5',
         COUNT(*) as Total
            FROM `oct_usergroup` u
                JOIN `oct_tickets` t
                ON (t.`Creator_SubType`= u.`Id`)
            WHERE
                t.Date_Created >= (CURDATE() -INTERVAL 49 DAY)
                AND u.Nama IS NOT NULL
                AND t.AgingCreateOrder between '1' and '1999'
                AND t.Status = 1
            GROUP BY u.`Nama`";

$result = mysql_query($vSQL)or die($vSQL."<br/><br/>".mysql_error());
while($row = mysql_fetch_array ($result))
    {
$Delim_String .= '
        <tr>
            <td>'.$row['Name'].'</td>
            <td>'.$row['Aging Less Than or Equal 5'].'</td>
            <td>'.$row['Aging More Than 5'].'</td>
            <td>'.$row['Total'].'</td>
        </tr>';
    }

$Delim_String .= "</tbody></table>";
$table1 = $Delim_String;
unset($Delim_String);

//===================Summary Aging Update Address start===========================
$Tab_info['Width'] = "600" ;
$Col_det = array(
    'Name' => array( 'Name',
                    'Aging Update Address ( <= 5 )',
                    'Aging Update Address ( > 5 )',
                    'Total'),
    'Size' => array( '200' ,  '200' ,  '200' ,  '100'  ),
    'Type' => array('sortable-text fd-column-', 'sortable-numeric fd-column-','sortable-numeric fd-column-','sortable-numeric fd-column-')
    );

$Delim_String = '<table id="Summary" class="sortable-onload-0-normal rowstyle-alt no-arrow" style="width:'.$Tab_info['Width'].'px;background-color:#FFFFFF;">
';
$Delim_String .= '<thead>
    <tr>
    ';
for ($Col_count = 0; $Col_count < sizeof($Col_det['Name']) ; $Col_count++) {
$Delim_String .= '
<th style="-moz-user-select: none;" class="'.$Col_det['Type'][$Col_count].$Col_count.'" width="'.$Col_det['Size'][$Col_count].'">';
$Delim_String .= '<a title="Sort on '.$Col_det['Name'][$Col_count].'" href="#">'.$Col_det['Name'][$Col_count].'</a>';
$Delim_String .= '</th>
';
}

$Delim_String .= '</tr>
  </thead>
  <tbody>
    ';


我希望它能像这样显示。

====================================================================
| Name     | Aging Create Order <=5 | Aging Create Order >5 | Total |
---------------------------------------------------------------------
| Consumer | 159                    | 80                    | 239   |
---------------------------------------------------------------------
| CSO      | 20                     | 50                    | 70    |
---------------------------------------------------------------------
| Total    | 179                    | 130                   | 309   |
=====================================================================


最后一行是要添加的行。

最佳答案

试试这个

$result = mysql_query($vSQL)or die($vSQL."<br/><br/>".mysql_error());

$gt_less = 0;
$gt_more = 0;
$gt_total = 0;
while($row = mysql_fetch_array ($result))
{
    $gt_less += $row['Aging Less Than or Equal 5'];
    $gt_more += $row['Aging More Than 5'];
    $gt_total += $row['Total'];
    $Delim_String .= '
    <tr>
        <td>'.$row['Name'].'</td>
        <td>'.$row['Aging Less Than or Equal 5'].'</td>
        <td>'.$row['Aging More Than 5'].'</td>
        <td>'.$row['Total'].'</td>
    </tr>';
 }
 $Delim_String .= '
    <tr>
        <td>Grand Total</td>
        <td>'.$gt_less.'</td>
        <td>'.$gt_more.'</td>
        <td>'.$gt_total.'</td>
    </tr>';

$Delim_String .= "</tbody></table>";

10-06 01:50