I am trying to pass multiple rows from database to client as response, but I can't achieve it! Error: {"src":null, "dest":null}
like this, but if i tried to echo
the $s
value there inside it prints the column values but its not passing.
Here is my code.:
$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);
}
it appears you are overriding $response["user"][...] at each iteration:
$response["user"][] = array(
"src" => $user[$j]['src'],
"dest" => $user[$j]['dest'],
);
Try this
$response["user"][]["src"]= $s;
$response["user"][]["dest"]= $d;
Instead of
$response["user"]["src"] = $s;
$response["user"]["dest"] = $d;