Reputation: 4760
I'm getting some unusual results after processing some data retrieved from a MySQL
table.
I have four fields of type float, two rows. All data is the same as you can see below:
Field1 = 5.0, 0.5
Field2 = 5.0, 0.5
Field3 = 5.0, 0.5
Field4 = 5.0, 0.5
I retrieve the data like so:
// 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);
So the results should all be the same right?
But the results of var_dump are:
float(2.75) float(2.5) float(2.75) float(2.75)
Why is $valueForMoney
2.5 when it should be 3?
Upvotes: 0
Views: 30
Reputation: 1309
It might just be a typo in the question, but you've got
$valueForMoney = ($ValueForMoney + $rating['value_for_money']);
PHP is case sensitive, so you probably meant...
$valueForMoney = ($valueForMoney + $rating['value_for_money']);
With a small "v" after the equals?
Upvotes: 1