繁体   English   中英

AngularJS获取后查询结果

[英]Angularjs getting result of post query

我正在BD MySQL中进行搜索,但无法获得所需的结果。 这是PHP代码

$mass = json_decode(file_get_contents('php://input'), true);
foreach ($mass as $mass_item) {
if($mass_item['name']=="Наименование" && isset($mass_item['val'])) 
$exp=$mass_item['val'];
}
$query = "SELECT * FROM Companies WHERE LOWER(name) RLIKE 
LOWER('".$exp."') ";
$result = mysql_query($query) or die();
while($row=mysql_fetch_array($result)){
    echo json_encode($row);
}

这是一个角度代码

    $http.post("search.php", value).then(function success (response) {
            console.log(response);
            console.log(response.data);
        },function error (response){
            console.log(response.data);
        }
    );`

结果,在控制台中,我看到空行“”。 但是,如果我在while之前或while再添加一个echo, while在控制台中像echo $row['name'] 我需要以json格式获取查询才能使用它。 请帮忙。

在此处输入图片说明

您试图回显每一行,将php代码更改为类似的内容:

$resultJson = [];
while($row=mysql_fetch_array($result)){
  $resultJson[] = $row;
}
echo json_encode($resultJson);
die;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM