I created 3 mysql tables:
table 'city': contains cities
i.e | name |
+========+
| Athens |
+--------+
| Rome |
+--------+
| Paris |
+--------+
table 'category': contains categories
i.e | name |
+============+
| category_1 |
+------------+
| category_2 |
+------------+
table 'shops': contains shops
i.e | name | category_name | city_name |
+========+=================+=============+
| shop_1 | category_2 | Rome |
+--------+-----------------+-------------|
| shop_2 | category_2 | Rome |
+--------+-----------------+-------------+
| shop_3 | category_1 | Paris |
+--------+-----------------+-------------+
I'm trying to create a single query that will allow me to create the following html array(that shows how many shops there are in each city grouped by category):
| || category_1 | category_2 |
+========++================+=============+
| Athens || 0 | 0 |
+--------++----------------+-------------|
| Rome || 0 | 2 |
+--------++----------------+-------------+
| Paris || 1 | 0 |
+--------++----------------+-------------+
Thank you in advance, Giannis