douxiawei9318 2014-02-13 20:38
浏览 30
已采纳

来自mysql的类比数据数据在PHP中不起作用

I am writing a code to get numerical data from mysql and then use that data to produce a scatter plot in jpgraphs.

    $f2 = "SELECT `COL 11` FROM `TABLE 1` WHERE 1 LIMIT 1,30;";
    $result1 = mysql_query($f2) or die("Cannot verify user " . mysql_error());
    if(mysql_num_rows($result1)>0)
    {
            $index1=0;
            while($present_row1= mysql_fetch_assoc($result1))
            {
                    $datay[$index1]=(float)$present_row1;
                    $index1++;
            }

    }

    print_r($datay);

When I typecast as float as the data is decimal values and print_r it I get the following output.

    Array ( [0] => 1 [1] => 1 [2] => 1)

But if don't typecast it the numerical values are there but they are in string format and I cannot plot them on graph.

    Array ( [0] => Array ( [COL 11] => -22039942 ) [1] => Array ( [COL 11] => -26151110 ) )
  • 写回答

1条回答 默认 最新

  • dtcyv3985 2014-02-13 20:43
    关注

    $present_row1 is an array, you can't cast it to a float.

    Try:

    $datay[$index1]=(float)$present_row1["COL 11"];
    

    (This is your $present_row1: Array ( [COL 11] => -22039942 ))

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64