在php中添加浮点值

时间:2012-03-07 04:10:24

标签: php math addition

鉴于下表:

type   |  valueOfType


food   |  4.3 

food   |  5.3

dairy  |  3.2

food   |  1.3

food   |  6.7

==============

我的查询需要搜索所有“food”类型并添加所有“valueOfType”,其中valueOfType是float类型。我该怎么做?

编辑:

$query = "SELECT SUM(valueOfType) AS Total FROM productTbl WHERE type ='$post_type' ";
$result = mysql_query($query2) 
or die("Unable to execute query because : " .     mysql_error());

echo $result;     

1 个答案:

答案 0 :(得分:5)

SELECT SUM(valueOfType) AS Total FROM foo WHERE type='food'