-1

我不确定为什么会发生这种情况,因为某些函数正在mysqli_fetch_assoc与 while 循环一起使用,而另一些函数mysqli_fetch_assoc在函数中的 while 循环中不起作用。

我使用了以下 PHP 脚本

function get_customer_record_list($table,$pos_customer){
        $sql = "SELECT * FROM ".$table." WHERE pos_customer = '$pos_customer' order by added_date DESC";
        $select =mysqli_query($this->connect,$sql)or die("Query (List) is not executed.");
        while($row = mysqli_fetch_assoc($select)){
            $result [] = $row;
        }
         echo "working";exit();

        //return $result;
    }

关闭值后不工作不打印while loop$result关闭循环后也不显示任何内容。

数据库中有501记录但数据不打印使用mysqli_fetch_assoc我也尝试mysqli_fetch_object使用foreach循环但数据不打印。

我不知道为什么会这样。

4

1 回答 1

-1

请检查,这应该工作。我已经添加了找到的行数的输出,然后打印了结果。

function get_customer_record_list($table,$pos_customer){
        $sql = "SELECT * FROM ".$table." WHERE pos_customer = '$pos_customer' order by added_date DESC LIMIT 3";
        $select =mysqli_query($this->connect,$sql)or die("Query (List) is not executed.");
        $rowcount=mysqli_num_rows($select);
        echo "Total Rows found-".$rowcount."\n<br>";
        $count=0;
        while($row = mysqli_fetch_assoc($select)){
            echo "Loop ".$count."\n<br>";
            $count++;

            $result[] = $row;
        }
        echo "Total Iterations -".$count."\n<br>";
        print_r($result);

        //return $result;
    }
于 2019-07-12T05:37:09.787 回答