[eluser]designcloud[/eluser]
Hello
Am hoping someone can help with this!
I have 3 tables
Profile (p_id, p_name, p_details)
Category (c_id, c_name)
Category Line (cl_id, c_id, p_id)
A profile can be associated with more than 1 category
A category can be associated with more and 1 profile
I want to show 4 random profiles on my sites homepage.
The div contains the profile name, as well as listing out all of the categories they are associated with.
<img>
profile name
<category name 1>, <category name 2>, <category name 3> etc etc
Any idea on how to get this to work?
Code:
SELECT *
FROM `profile`
INNER JOIN `category_line` ON `profile`.`profile_id` = `category_line`.`profile_id`
INNER JOIN `category` ON `category`.`category_id` = `category_line`.`category_id`
GROUP BY `profile`.`profile_id`
This is what I have so far, however its only returning the name of the profile, without the category names they are associated with. Any ideas on what SQL i need to use, and how to return the results in an array in the model.