普通网友 2016-01-06 14:13
浏览 33
已采纳

非空的变量,表示未定义的变量

Please check out the below code.

        $key = $_SESSION['order_nums'];
        $sqll = "SELECT * FROM `money` WHERE `order` = :key";
        $qq=$con->prepare($sqll);
        $qq->bindvalue(":key", $key);
        $qq->execute();


        $excel2 = PHPExcel_IOFactory::createReader('Excel2007');
        $excel2 = $excel2->load('nTest.xlsx'); // Empty Sheet
        $excel2->setActiveSheetIndex(0);
        $worksheet = $excel2->getActiveSheet();

        $Cno = '7';
        $COno = '7';
        $MSno = '7';
        $CHno = '7';
        $ALno = '7';


        while($fdata=$qq->fetch(PDO::FETCH_ASSOC))
        {   

                $totalCost += $fdata['cost'];


                /*
            $worksheet
                ->setCellValue('A' . $Cno++, $fdata['code'])
                ->setCellValue('D' . $COno++, $fdata['cost'])
                ->setCellValue('E' . $MSno++, $fdata['time'])
                ->setCellValue('F' . $CHno++, $fdata['hourly'])
                ->setCellValue('G' . $ALno++, $fdata['ot']);*/




        }

Ok, so the part of the code where it says $totalCost += $fdata['cost'] is saying its a undefined variable. Yet the code below it that I commented out.. If I uncomment it, it works perfect.

  • 写回答

1条回答 默认 最新

  • douhuan6157 2016-01-06 14:15
    关注

    you didn't define $totalCost variable before using it, so you should define it outside while loop $totalCost = 0;

    $totalCost = 0;
    while($fdata=$qq->fetch(PDO::FETCH_ASSOC))
            {   
    
                    $totalCost += $fdata['cost'];
    
    
                    /*
                $worksheet
                    ->setCellValue('A' . $Cno++, $fdata['code'])
                    ->setCellValue('D' . $COno++, $fdata['cost'])
                    ->setCellValue('E' . $MSno++, $fdata['time'])
                    ->setCellValue('F' . $CHno++, $fdata['hourly'])
                    ->setCellValue('G' . $ALno++, $fdata['ot']);*/
    
    
    
    
            }
    

    because this line $totalCost += $fdata['cost']; means $totalCost = $totalCost + $fdata['cost']; and in this case it didn't find the var $totalCost

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

报告相同问题?

悬赏问题

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