PHP Knowledge Base
MySQL SUM() function - PHP PDO
Example #1
$dbh = new PDO("MySQL:host=$hostname;dbname=$db", $username, $password); foreach($dbh->query('SELECT SUM(total_cost) FROM purchase') as $row) { echo "<tr>"; echo "<td>" . $row['SUM(total_cost)'] . "</td>"; echo ""; }
Example #2
$sql__total__seventh = "SELECT SUM(total) FROM $whichTable2"; echo "<tr>\n"; echo "<td>TOTALS</td>"; foreach($conn->query($sql__total__seventh) as $row__total__seventh) { $total__seventh = $row__total__seventh['SUM(total)']; echo "<td>$total__seventh</td>"; }