Page 1 of 1

ARRAY Question ...

Posted: Mon Nov 24, 2003 4:04 pm
by nwoutback
I'm using this to pull all columns from a table and list column names and SUMS ... I've got 8 distributors in this table, and I'd like to pull columns and SUMS of, per distributor ... How?

<?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 WHERE RptDist = 'Gardner'";
$mysqlresult = mysql_query($query);
$result = mysql_fetch_array($mysqlresult);
echo "{$columns} : {$result[0]}<br />";
mysql_free_result();
}

?>

Posted: Fri Aug 27, 2004 1:20 am
by Lord Sauron
First of all you should request the distributor name in the query if you want this to work. Secondly, your trying to 'sum' $columns? Isn't the result always 1?

Secondly, I would be able to help you, of you would tell me, what your db table structure looks like.