bna747 Posted October 9, 2013 Share Posted October 9, 2013 <table border="1"> <tr> <td>test_id</td> <td>fruits</td> <td>vegetables</td> <td>meats</td> <td>poultry</td> <td>Totals</td> </tr> <?php do { ?> <tr> <td><?php echo $row_Recordset1['test_id']; ?></td> <td><?php echo $row_Recordset1['fruits']; ?></td> <td><?php echo $row_Recordset1['vegetables']; ?></td> <td><?php echo $row_Recordset1['meats']; ?></td> <td><?php echo $row_Recordset1['poultry']; ?></td> <td><?php $test1=$row_Recordset1['fruits'];; $test2=$row_Recordset1['vegetables']; $test3=$row_Recordset1['meats']; $test4=$row_Recordset1['poultry']; $testtotal=$test1+$test2+$test3+$test4; if ($testtotal == '0') { echo '0.00'; }else { echo "$" . number_format($testtotal, 2, '.', ','); } ?></td> </tr> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> </table> <div> Need the sum of all in the "Totals" column to echo here (value should be $84.00) </div> I have a table that has values in each column and php code to add up all values in each row to output the total dollar amount on each row. I having a very difficult time trying to echo out the sum of all rows only in the "TOTALS" column. The totals column of the table is not a field in the database table that stores the totaltest-table.tiff. Can anyone help with a solution to this problem? Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted October 9, 2013 Share Posted October 9, 2013 (edited) So want the add up the subtotals of $testtotal. You'll wan't to have another variable, call this variable $total_sum. So after $testtotal=$test1+$test2+$test3+$test4; add $total_sum += $testtotal; Then before the </table> add <tr><td colspan="5"></td><td><?php echo $total_sum; ?></td></tr> Edited October 9, 2013 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
bna747 Posted October 9, 2013 Author Share Posted October 9, 2013 PERFECT! Works Great. Thank you very much for the quick rapid response. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.