[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 205
  • Last Modified:

Total Amount for a Table Row

Hi,

I have the following table that will for example display results like the following:

Y          20          N
N          55          N
Y          18          Y
N          11          N
Y          96          N

12.81   1.94       0.10 <---------- I am trying to get the total for this row

Can I get the total for the last row of numbers and display it below the data?

Here is the PHP Code:

<?php

echo "<table cellpadding=\'2\' cellspacing=\'0\'>";

echo "<tr>";
echo "<td class=\"th\" >col1</td>";
echo "<td class=\"th\" >col2</td>";
echo "<td class=\"th\" >col3</td>";

if($result && mysql_num_rows($result) > 0)
{    for ($i = 0; $i < mysql_num_rows($result); $i++) {
    $resultArray[$i] = mysql_fetch_array($result);
}

foreach ($resultArray as $val) {
   echo ('<tr>');//first row
   if (($rowcount%2) == 0) {
        $css_class = "\"row\"";
    } else {
        $css_class = "\"alt\"";
    }

      echo ('<td class=' . $css_class . ' align=default >'.$val[1].'</td>');
      echo ('<td class=' . $css_class . ' align=default >'.$val[2].'</td>');
      echo ('<td class=' . $css_class . ' align=default >'.$val[3].'</td>');
    echo ('</tr>');
}

    echo ('<tr>');//second row
      echo ('<td class=' . $css_class . ' align=default >'.$resultArray[0][4].'</td>');
      echo ('<td class=' . $css_class . ' align=default >'.$resultArray[0][5].'</td>');
      echo ('<td class=' . $css_class . ' align=default >'.$resultArray[0][6].'</td>');
    echo ('</tr>');


} // end if results
echo ('</table>');

?>

0
fcruz5
Asked:
fcruz5
1 Solution
 
Terry WoodsIT GuruCommented:
Something like this?:

...
    echo ('<tr>');//second row
      echo ('<td class=' . $css_class . ' align=default >'.$resultArray[0][4].'</td>');
      echo ('<td class=' . $css_class . ' align=default >'.$resultArray[0][5].'</td>');
      echo ('<td class=' . $css_class . ' align=default >'.$resultArray[0][6].'</td>');
    echo ('</tr>');
   $total = $resultArray[0][4] + $resultArray[0][5] + $resultArray[0][6];
    echo "<tr><td colspan=3>Total = $total</td></tr>\n";
...
0
 
fcruz5Author Commented:
Yes, Thanks!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now