I want to send 3 tables in my MySQL (PDO) using json. There is a loop in the first table Note: First table (fetchAll) Second table (fetch) Third table (fetch)
$stmt1 = $db->prepare("SELECT * FROM data WHERE countid='1'");
$stmt1->execute();
$data = $stmt1->fetchAll(PDO::FETCH_OBJ);
$stmt2 = $db->prepare("SELECT id,title FROM weeks WHERE id='2'");
$stmt2->execute();
$data->weeks[] = $stmt2->fetch(PDO::FETCH_OBJ);
$stmt3 = $db->prepare("SELECT id,name FROM user WHERE id='1'");
$stmt3->execute();
$data->user[] = $stmt3->fetch(PDO::FETCH_OBJ);
$response = new stdClass();
$response->data[] = $data;
echo json_encode($response);
See Question&Answers more detail:os