SUM ()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nwoutback
Forum Newbie
Posts: 17
Joined: Mon Nov 24, 2003 1:50 pm

SUM ()

Post by nwoutback »

I'm trying to get a list of all columns and their associated SUM values, but the code I'm using below only displayed the first column and it's SUM value .. can you see where I might be missing something that the other columns and SUM values aren't being displayed? Thanks.

<?php

$connection=mysql_connect("localhost","user","pw") or die('Could not connect to the database server');
$db = mysql_select_db("tanaka-ism_com", $connection) or die ("Unable to select database.");

$columns = array("AST210","AST210Sales","TBC2251", "TBC2251Sales");

foreach($columns as $columns)
{
$query = "SELECT SUM($columns) FROM distreport03";
$mysqlresult = mysql_query($query);
$result = mysql_fetch_array($mysqlresult);
echo "{$columns} : {$result[0]}<br />";
musql_free_result();
}

?>
Post Reply