counting a field
Posted: Mon Feb 20, 2006 4:58 am
Hi all
I have records of transactions that take plac on my website held in a database.
What I want to do is display the transactions per product. So I am trying to add together each transaction per product.
I am having a little problem displaying this accumulated price.
My code is as follows;
and my query is
at present all that is displayed is the product ID
any ideas as to why it is not working?
thanks in advance
I have records of transactions that take plac on my website held in a database.
What I want to do is display the transactions per product. So I am trying to add together each transaction per product.
I am having a little problem displaying this accumulated price.
My code is as follows;
Code: Select all
$result2 = admin_activity_transactions_query();
while ($row2 = mysql_fetch_array($result2))
{
$product_id = $row2['product_id'];
$trans_price = $row2['trans_price'];
print '<p>'.$product_id.', '.$trans_price.'</p>';
}Code: Select all
function admin_activity_transactions_query()
{
db_connect();
$result = mysql_query("Select product_id, SUM(trans_price) from transactions group by product_id") or die(mysql_error());
return $result;
}any ideas as to why it is not working?
thanks in advance