I had a two table,
First one : table product table product
| id | name | code |
| 1 | blouse | AB1 |
| 2 | jeans | BA2 |
| 3 | dress | C61 |
and the second table color table color
| id_product | colors | amount |
| 1 | blue | 50 |
| 1 | red | 40 |
| 1 | yellow| 10 |
| 2 | white | 15 |
| 2 | blue | 60 |
| 3 | purple| 110 |
Query : my query php
.../blabla
SELECT product.id, product.name, product.code,color.id_product, color.colors, color.amount
FROM product
INNER JOIN color
ON product.id = color.id_product limit 1
while($query)) {
$var[] = $query;
}
echo '{"status":'. json_encode($var).'}';
OUTPUT :
{
"status":{
"1":{
"id":"1",
"code":"blouse",
"id_product":"1",
"colors":"blue",
"amount":"50",
}
}
}
what i want JSON like this :
{
"status":{
"1":{
"id":"1",
"code":"blouse",
"id_product":"1",
"colors":"blue",
"amount":"50",
"id_product":"1",
"colors":"red",
"amount":"40",
"id_product":"1",
"colors":"yellow",
"amount":"10",
}
}
}
Need color into one array json, is that possible?