Ok, I have an app as described in this post: http://stackoverflow.com/questions/1623105/good-database-structure-for-a-new-web-app
I've prepared a scenario to make my question as clear as possible:
Users table:
+----------+-----------------+
| user_id | email |
+----------+-----------------+
| user_1 | [email protected] |
| user_2 | [email protected] |
| user_3 | [email protected] |
| user_4 | [email protected] |
+----------+-----------------+
*Notice user_3 and user_4 do not have their own domains
Domains table:
+-----------+------------+
| owner_id | domain |
+-----------+------------+
| user_1 | dom-1.com |
| user_1 | dom-2.com |
| user_2 | dom-3.com |
+------------------------+
The table below, shows who is a user of a domain and who the owner is:
User-Domain table:
+----------+-------------+-----------+
| user_id | domain | owner_id |
+------------------------+-----------+
| user_1 | dom-1.com | user_1 |
| user_1 | dom-2.com | user_1 |
| user_2 | dom-3.com | user_2 |
| user_3 | dom-1.com | user_1 |
| user_3 | dom-2.com | user_1 |
| user_4 | dom-1.com | user_1 |
+------------------------+-----------+
My question is, how do I output a list of each user who is using a given user's domain, in the following format?
For example (the following is an HTML table):
List of users who are using User_1's domains (HTML TABLE):
+-------------------+-----------------------+
| Email | domains |
+-------------------+-----------------------+
| [email protected] | dom-1.com, dom-2.com |
| [email protected] | dom-1.com |
+-------------------+-----------------------+