MySQL
在处理从表中检索到的一些数据后,我得到了一些不寻常的结果。
我有四个浮点类型的字段,两行。所有数据与您在下面看到的相同:
Field1 = 5.0, 0.5
Field2 = 5.0, 0.5
Field3 = 5.0, 0.5
Field4 = 5.0, 0.5
我像这样检索数据:
// Get ratings for this event
$eventRating = $event->getEventRatings($event_id);
$organisation = 0;
$valueForMoney = 0;
$facilities = 0;
$funFactor = 0;
$overall = 0;
foreach($eventRating AS $rating){
$organisation = ($organisation + $rating['organisation']);
$valueForMoney = ($ValueForMoney + $rating['value_for_money']);
$facilities = ($facilities + $rating['facilities']);
$funFactor = ($funFactor + $rating['fun_factor']);
}
// Get average of each rating category
var_dump($organisation = $organisation /$ratingCount);
var_dump($valueForMoney = $valueForMoney /$ratingCount);
var_dump($facilities = $facilities /$ratingCount);
var_dump($funFactor = $funFactor /$ratingCount);
所以结果应该都是一样的吧?
但是 var_dump 的结果是:
浮动(2.75) 浮动(2.5) 浮动(2.75) 浮动(2.75)
为什么$valueForMoney
应该是 3 却是 2.5?