Is there a way to get the sum of all the values in an array, from a MySQL database?? Look at this snippet:
In line 83 I'd like $total to contain the sum of all the values in $myrow['CPO'], kind'a like in an excel sheet. In my database, feild CPO contains integer values. Can I do that or am I just nuts? .:TUCK:.
Code:
67<?php
68if(!empty($result)){
69 while ($myrow = mysql_fetch_array($result)) {
70 echo "<tr>";
71 printf("<td bgcolor=\"#FFFFFF\" align=\"center\">%s</td>", $myrow['id']);
72 printf("<td bgcolor=\"#FFFFFF\" align=\"center\">%s</td>", $myrow['date_time']);
73 printf("<td bgcolor=\"#FFFFFF\" align=\"center\">%s</td>", $myrow['name']);
74 printf("<td bgcolor=\"#FFFFFF\" align=\"center\">%s</td>", $myrow['items']);
75 printf("<td bgcolor=\"#FFFFFF\" align=\"center\">%s</td>", $myrow['mgr']);
76 printf("<td bgcolor=\"#FFFFFF\" align=\"center\">%s</td>", $myrow['hws']);
77 printf("<td bgcolor=\"#FFFFFF\" align=\"center\">%s</td>", $myrow['leads']);
78 printf("<td bgcolor=\"#FFFFFF\" align=\"center\">%s</td>", $myrow['CPO']);
79 echo "</tr>";
80 }
81 }
82
83$total = sum($myrow['CPO']);
84
85echo "<tr>";
86printf("<td colspan="6"></td><td bgcolor=\"#FFFFFF\" align=\"center\">Total</td><td bgcolor=\"#FFFFFF\" align=\"center\">$total</td>");
87echo "</tr>";
88?>