[英]Displaying an array in angular.js
I'm sending data of to a php file and the php file is processing and doing a sql search and its bringing back a list in a for each statement, for example: ryan, jack, billy, sarah 我正在发送一个php文件的数据,php文件正在处理并进行sql搜索,并在每个语句中返回一个列表,例如:ryan,jack,billy,sarah
etc 等等
when I echo the response, in angular, i'm getting all the names joined up like: ryanjackbillysarah 当我回应这个回应时,在角度上,我得到了所有的名字,如:ryanjackbillysarah
How can I show this on the page in a list so like: Ryan Jack Billy Sarah 如何在列表中的页面上显示如下:Ryan Jack Billy Sarah
This is my php 这是我的PHP
$result = mysqli_query( $connect, $sql);
if($result){
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$list .= $row["firstname"];
}
}
echo $list;
This is my angular success, function. 这是我的角色成功,功能。
// Success call back function.
request.then(function successCallback(response) {
//alert(response.data);
alert(response.data);
},
Just use json_encode in your php to return a JSON to angular. 只需在php中使用json_encode将JSON返回到angular。
$result = mysqli_query( $connect, $sql);
if($result){
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$list[] = $row["firstname"];
}
}
echo json_encode($list);
This is because you are concatenating each list item in a string. 这是因为您将字符串中的每个列表项连接起来。 You have to separate them in some way or return the list and make the foreach angular . 你必须以某种方式将它们分开或返回列表并使foreach成为有角度的。
I think that's what I do not understand much about php . 我认为这是我对php不太了解的。 Try putting a space. 试着放一个空间。
$result = mysqli_query( $connect, $sql);
if($result){
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$list .= $row["firstname"] . ' ';
}
}
echo $list;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.