I was correctly getting the SUM of my 'amount' column from my transactions table. But I was also only querying just the transactions table. Now I am trying to query 2 tables, but with the same results.
This is the query that works - it is querying only 1 table:
It will print a dollar amount like: $5.66
$sum = mysql_query("SELECT SUM(amount) FROM transactions WHERE type = 'sale' AND dateCreated BETWEEN '$startdate' AND '$enddate' AND product_id = '$product_id'");
while($row = mysql_fetch_array($sum)){
$total = $row['SUM(amount)'];
}
echo money_format('%i', $total);
Now, this is the query that does not display the totaled amount, and it stopped working when I added the customers table in the query:
$sum = mysql_query("SELECT SUM(t.amount), c.* FROM transactions t , customers c WHERE t.customer_id = c.customer_id AND t.type = 'sale' AND c.misc2 = '2' AND t.dateCreated BETWEEN '$startdate' AND '$enddate' AND t.product_id = '$product_id'");
while($row = mysql_fetch_array($sum)){
$total = $row['SUM(amount)'];
}
echo money_format('%i', $total);
Am I using SUM wrong?