Page 1 of 1

mysql / php array the category (quick help pleas)

Posted: Wed Oct 31, 2007 9:48 am
by spamyboy
PHP / MySql code:

Code: Select all

$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:

Code: Select all

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:

Code: Select all

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:

Code: Select all

categories:
category_id | category_title
categories_relations:
category_id | gallery_id
galleries:
gallery_id, gallery_title

Posted: Thu Nov 01, 2007 5:38 am
by spamyboy
anyhelp?

Posted: Thu Nov 01, 2007 9:58 am
by seppo0010
I don't get what you want... you want to have an array with two values on the same key (gallery_id and category_title)?
If that's correct, it is not posible :S