Count database-values

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi everybody,

I've got a little problem, which I can't solve. It is as follow:
In my database I made a table with different fields.
One of the fields is named 'bedrag' and contains a numeric value like 15.47 or 78.16 and so on.
If I want a value of the table I use in most cases the following code:

<?
$squery = mysql_query("SELECT * FROM finance WHERE posneg = 'af'",$db);
while($row = mysql_fetch_array($squery)) {

$bedrag = $row["bedrag"];
echo "$bedrag<br>";
}
?>

In this case I receive a list like:
15.47
78.16
and so on...

So far no problems, but I want to count all these values. I tried with SUM but with the following code it doesn't work:

$squery = "SELECT SUM(bedrag) AS Total FROM finance WHERE posneg = 'af'";

any suggestions how to do? I want to store it in a variabele ($total) so I can echo it. (E.g.: $total = 93.63 in this case)

Thanx in advance,

Robert van der Mast


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux