PHP / MySql code:
$query=$galleryCMS->db->query("
SELECT galleries.gallery_id, categories.category_title, galleries.gallery_title
FROM galleries JOIN categories_relations USING (gallery_id) JOIN categories USING (category_id)
WHERE gallery_id='2'
");
while($row=$galleryCMS->db->fetch_array($query)){
print_r($row);
}
Result:
Array ( [gallery_id] => 2 [category_title] => apps [gallery_title] => test ) Array ( [gallery_id] => 2 [category_title] => games [gallery_title] => test )
And how I imagine correct result, would be:
array([gallery_id] => 2 [category_title] => apps,[gallery_id] => 2 [category_title] => games) gallery_title
Thank you in advance.
p.s. people said me to use GROUP_CONCAT, but it's alitle bit to dificul on how to use it since I didnt managed to find a tutorial on it, but anyway, I would like to do it without creating another while session (if that is possible), thank you in advance.
edited: seems that GROUP_CONCAT is alitle bit off-topic stuff here, it might be used if you put all categories in one row (by id or title), but in my situation I'm using relations table (as you can probaly see from query that is given), that is db structure looks like:
categories:
category_id | category_title
categories_relations:
category_id | gallery_id
galleries:
gallery_id, gallery_title