fcruz5
asked on
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].'</t d>');
echo ('<td class=' . $css_class . ' align=default >'.$resultArray[0][5].'</t d>');
echo ('<td class=' . $css_class . ' align=default >'.$resultArray[0][6].'</t d>');
echo ('</tr>');
} // end if results
echo ('</table>');
?>
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].'</t
echo ('<td class=' . $css_class . ' align=default >'.$resultArray[0][5].'</t
echo ('<td class=' . $css_class . ' align=default >'.$resultArray[0][6].'</t
echo ('</tr>');
} // end if results
echo ('</table>');
?>
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER