I have three different tables:
holidays:
id | date | title | description
cat_event:
id | eventId (fk: holidays.id) | catId (fk: categories.id)
categories:
id | catName
One event can contain one or more categories.
I'd like to create the following JSON:
{
"Events":
[
{
"id": "12",
"date": "2014.03.21",
"title": "National Tiger Day",
"description": "Some description text",
"categories":
[
{ "id": "1", "catName": "Animal" },
{ "id": "2", "catName": "Global" }
]
},
{
"id": "13",
"date": "2014.03.22",
"title": "World Chocolate Day",
"description": "Some description text",
"categories":
[
{ "id": "3", "catName": "Food" },
{ "id": "2", "catName": "Global" }
]
}
]
}
I made a query:
SELECT holidays.*, categories.* FROM holidays JOIN event_cat ON event_cat.eventId = holidays.id JOIN categories ON categories.id = event_cat.catId WHERE holidays.id = 1
But I really don't have a clue how I can create the mentioned json array.