I've 2 tables, I want to get data from the first one depends on "id", and the data from second one depends on the "gid" that same as "id" from the first table, in JSON.
Example:
First Table:
- - - - - - -
id name
1 Aaron
2 Caleb
3 Albert
4 Ethan
Second Table:
- - - - - - -
id gid image
1 1 http://.......image1.jpg
2 1 http://.......image2.jpg
3 2 http://.......image3.jpg
4 3 http://.......image4.jpg
5 3 http://.......image5.jpg
6 3 http://.......image6.jpg
I want the result when I request id=1, Something like this:
"names": [
{
"id": 1,
"name": "Aaron"
"images":[
{
"id" :1
"url":http://.......image1.jpg
},
{
"id" :2
"url":http://.......image2.jpg
}
]
}
]
This some of my code:
$SqlInfo = "Select * from tabel1 where id='$id'";
$obj = json_decode($_GET["x"], false);
$stmt = $con->prepare($SqlInfo);
$stmt->bind_param("ss", $obj->table, $obj->limit);
$stmt->execute();
$result = $stmt->get_result();
$outp = $result->fetch_all(MYSQLI_ASSOC);
echo json_encode(array(
'status' => 'Ok',
'name' => $outp
));
to be more specific, my above code , bring json format for the first table, I want to insert the result of the second table in the same result of json (of the first table). Thank you ...