Linked Questions

Popular Questions

SUM of all rows from WHERE condition?

Asked by At

I'm trying to add the contents of all the rows retrieved from a query.

So far I have tried:

$totalquery = "SELECT SUM(catalogue.price) AS fCount
        FROM catalogue LEFT JOIN orders ON catalogue.plantid = orders.orderplantid
        WHERE orders.orderplantid = '$actualresult' AND orders.ordercustomerid = '$actualresult2' GROUP BY catalogue.price";
        $result3 = mysql_query($totalquery) or die ("Query failed : " . mysql_error());
        $totalresult = mysql_result($result3,0);

and then echoing out the $totalresult, but the problem is only displays the last value, rather than the sum of all of the values selected - any ideas on where I'm going wrong?

Related Questions