dongmi1872 2013-10-02 13:27
浏览 16

拉数据MySQL后奇怪的结果

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?

  • 写回答

1条回答 默认 最新

  • dongniuxia8650 2013-10-02 13:31
    关注

    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?

    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题