php变量范围外循环

时间:2015-11-13 12:16:04

标签: php mysql sql

我试图在循环中保存一些结果,然后将名为$ hello的外部变量修改为'123',然后在循环外面打印它。

$hello = 'hi';
        // SQL //
        if ($stmt = $this->dbCon->prepare($sql)) {
            //$stmt->bind_param("s", $chainid);
            call_user_func_array(array($stmt, 'bind_param'), $params);
            $stmt->execute();
            $stmt->bind_result($sysid, $branchid, $harddiscount);
            while ($stmt->fetch()) {
                $harddiscount = number_format($harddiscount / 100, 2) . "€";

                //echo $couponname ."*".$trustanduseid."({$clientid})*".$productname."*".$chainname."*".$branchname."*".$receiptdate."*".$companyname."*".$brandname."*".$receiptid."*".$counterid."*".$discountvalue."*";
                //echo $couponname ."*".$trustanduseid."({$clientid})*".$productname."*".$chainname."*".$branchname."*".$receiptdate."*".$companyname."*".$brandname."*".$receiptid."*".$counterid."*".$harddiscount."*";

                $hello = '123';
            }
            $stmt->close();
        }

        echo $hello;

上面打印'hi'而不是'123';

我怎样才能解决它?

0 个答案:

没有答案
相关问题