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条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度