duanfengwang9157 2013-02-28 16:48
浏览 108
已采纳

floatval返回1 php错误

I have a mysql table with float variables. I want to pass them to mongodb collection, but when i do it, php convert my float variables into string. I've tried to use this code to set variable type as float but it returns me 1 in every field:

foreach( $mytables as $table => $struct ) {
  $sql = mysql_query("SELECT num_auto FROM XL_10331_EXPLOIT_251012 where flightid like '191622'") or die( mysql_error() );
  $count = mysql_num_rows( $sql );
  // If it has content insert all content
  if( $count > 0 ) {
    while($info = mysql_fetch_row($sql)) {
        $int_info=intval($info);
          $mosql[]=($int_info);
  }

   // Starts new collection on mongodb
  $collection = $modb->floatdb;

  $collection->insert(array('num_auto'=>$mosql));

i can't find my mistake, any help will be really appreciated! Thanks!

  • 写回答

2条回答 默认 最新

  • duanlinzhen7235 2013-02-28 16:52
    关注

    mysql_fetch_row returns an array, not a value. So you have to use:

    $int_info = (float)$info[0];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序,怎么查看客户esp32板子上程序及烧录地址
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址