PHP - SUM function problem - Asked By Olusegun A. on 04-Aug-10 05:39 AM

Hello friends,

am having problem with my SUM function. I tried summing up some figures in a column but is not returning the total of the figures. this is my syntax

<?php

include("config.php");
$column='amount';
$table='transactions'

$creditbal=mysql_query("SELECT SUM($column), FROM $table WHERE status='P'");

$rows=mysql_fetch_array($creditbal);

echo $creditbal;

?>

but is not echoing any out any, what can i do.

Regards,
adsegzy

Ken Fitzpatrick replied to Olusegun A. on 04-Aug-10 05:42 AM
Olusegun,

Remove the comma between SUM($column) and FROM. That is causing it to fail.

Ken
Super Man replied to Olusegun A. on 04-Aug-10 05:47 AM
you should have to write query like this:

you don't need to write comma after column.

SELECT SUM($column) FROM $table WHERE status='P'"