PHP Json响应仅返回最后一行

PHP Json响应仅返回最后一行,php,json,Php,Json,您好,我正在尝试使用AngularJS运行此代码行,但只是获取数据集的最后一行,我在一些站点中看到了此示例,我不知道是否缺少一些配置: $result = $mysqli->query ($query ) or die( $mysqli->error . __LINE__ ); $arr = array(); if($result->num_rows > 0) { while($row = $result->fetch_assoc()) {

您好,我正在尝试使用AngularJS运行此代码行,但只是获取数据集的最后一行,我在一些站点中看到了此示例,我不知道是否缺少一些配置:

$result = $mysqli->query ($query ) or die( $mysqli->error . __LINE__ );

$arr = array();
if($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
       $arr['data'] = $row;
    }
}

# JSON-encode the response
echo $json_response = json_encode($arr);

谢谢

这行只是用数组覆盖了
$arr['data']

$arr['data'] = $row;
换成

$arr['data'][] = $row;

这将把行作为一个数组推送到
$arr['data']

感谢您的响应,我更改了这一行,并在控制台中得到这个结果:Object{data:,status:200,config:Object,statusText:“OK”}config:Objectdata:“headers:(c)status:200statusText:“OK”proto:Object,数据为空代码中的何处显示控制台的输出?请包括所有相关代码!我知道它是有效的,因为我在教程中看到过,我不知道我的例子中有什么错误,我在app.js var data={}中使用了XAMPPIn控件;SelEstados.getRequest(data).then(函数(result){//success console.log(result);console.log(result.data);//$scope.estados=result.data;},函数(result){//error console.log(result.data);};非常感谢您的帮助,经过大量测试,这是一个带有json_编码的特殊字符管理