我试图将多行从数据库传递给客户端作为响应,但我无法实现它! Error: {"src":null, "dest":null}
是这样的,但如果我尝试echo
里面的$s
值,则会打印列值,但不会传递。
这是我的代码。:
$c=$db->getcount($dest);
$user = $db->getUserByEmailAndPassword($dest);
if ($user != false) {
$response["success"] = 1;
for($j=0;$j<=$c;$j++) {
$s= $user[$j]['src'];
$d =$user[$j]['dest'];
$response["user"]["src"] = $s;
$response["user"]["dest"] = $d;
}
echo json_encode($response);
}
答案 0 :(得分:1)
试试这个
$response["user"][]["src"]= $s;
$response["user"][]["dest"]= $d;
而不是
$response["user"]["src"] = $s;
$response["user"]["dest"] = $d;
答案 1 :(得分:0)
看起来你在每次迭代时都会覆盖$ response [“user”] [...]:
$response["user"][] = array(
"src" => $user[$j]['src'],
"dest" => $user[$j]['dest'],
);