I got a minor problem. To start, I have the following tables: ‘groups’, ‘pages’ and the junction table ‘subcriptions’
The idea behind this is that a group (with users) can subsribe to a page. An user can add a page as a subscription to the group he is in. (many-to-many). For information: An user can be in multiple groups.
As a part of the UI I want to make a list about that. From every group I want the associated pages. For example: (Group: … Pages: -…. , -…. | Group: … Pages: -…., -…. etc.)
The SQL query is not a issue:
SELECT Groups.name, pages.name, pages.id
FROM Groups
JOIN subscriptions ON groups.id = subscriptions.group_id
JOIN pages ON subscriptions.page_id = pages.id
WHERE groups.id IN ('1', '2') // de values 1 & 2 zijn voorbeelden en stellen de groepen id's voor waarin de huidige gebruiker zit.
The result will, for example, look like this:
group name ---- page name ---- page id
group1 -------- page1 --------- 1
group1 -------- page2 --------- 2
group2 -------- page1 --------- 1
My question is; how can I get a (html) list where I get a single group-name and all the associated pages to that group? (Like the example I mentioned earlier). I need a php solution. (I am using Zend framework, but I could not find a solution in Zend that does the trick I want)
Or do have to do a single query for every group? I would like to avoid that though..
I am new in this world of mysql and php so every help is worth allot! Thanks. 🙂
a very basic implementation would be the following:
cheers 🙂