0

我正在尝试将多行从数据库传递到客户端作为响应,但我无法实现!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);  
}
4

2 回答 2

1

尝试这个

  $response["user"][]["src"]= $s;
  $response["user"][]["dest"]= $d;  

代替

  $response["user"]["src"] = $s;
  $response["user"]["dest"] = $d;  
于 2012-12-17T13:25:00.010 回答
0

看来您在每次迭代时都覆盖了 $response["user"][...] :

$response["user"][] = array(
    "src" => $user[$j]['src'],
    "dest" => $user[$j]['dest'],
);
于 2012-12-17T13:24:35.563 回答