i am trying selecting(B) data from mysql in another selecting(A), but i get an error from the selecting(B). I have no idea how to fix it and find the problem of it.
// the server connection code id omitted.
// the code below has been edited. $bookId= $_POST["bookId"];
$sql = "SELECT * FROM feedback WHERE bookId= '".$bookId."'";// selecting(A)
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$sql = "SELECT * FROM userInfo WHERE userId= '". $row["userId"]."'"; //selecting(B)
$data = mysqli_query($conn, $sql);
$userData = mysql_fetch_array($data);
$Arr = array("userId" => $userData ["userId"], "userName" => $userData ["userName"],
"feedback" => $row["feedback"], "date" => $row["date"]);
$feedbackArray[] = array("feedbackDetail"=> $Arr);
}
}
mysqli_close($conn);
$json= array("feedback" => $feedbackArray);
echo json_encode($json);
the result i got: an error + a valid json (but has null:( )
{"feedback":[{"feedbackDetail":{"userId":null,"userName":null,"feedback":"I love you ba~~","date":"2016-03-19 21:48:46"}},{"feedbackDetail":{"userId":null,"userName":null,"feedback":"well!!!","date":"2016-03-19 21:46:52"}}]}
any idea?