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>');

?>

fcruz5Asked:
Who is Participating?
 
Terry WoodsConnect With a Mentor IT 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.