Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Query with Group Concat



3:28 pm on Jul 31, 2011 (gmt 0)

10+ Year Member

Hi there,

I have a query where I am trying to retrieve some data and place in an array within an array. So I have this query

GROUP_CONCAT(notes.notes_ids Separator "~") as allids
GROUP_CONCAT(notes.notes Separator "~") as allnotes
FROM customer as c
LEFT JOIN notes on notes.customer_id_fk = c.customer_id
GROUP BY c.customer_id

then the while part

while($row = mysql_fetch_assoc($result)){

$customer = $row;

$customer[$row[notes]]['new_ids'] = explode('~', $customer[$row]['allids']);
$customer[$row[notes]]['new_notes'] = explode('~', $customer[$row]['allnotes']);


There may be some confusing bit there as I haven't tested that, just writing off hand.

Anyway what I get from customer when print_r the array is something like this:

[0]=>[name] =>customername
and then i end up with
[new_ids] =>array( [0]=>1 [1]=>2)
[new_notes =>array([0]=>a note [2]=>another note)

What I would like to end up with in the main array is

[notes] =>array([0][new_ids] = 1 [new_notes] = a note
[1][new_ids] = 2 [new_notes] = another note)

so that the notes array is nice an easy to loop through.

What am I doing wrong? Is there a way to do what I am trying to get at?



7:44 am on Aug 1, 2011 (gmt 0)

5+ Year Member

I'm not really sure but from what I see you should only change:

$customer[$row[notes]]['new_ids'] = explode('~', $customer[$row]['allids']);
$customer[$row[notes]]['new_notes'] = explode('~', $customer[$row]['allnotes']);


$customer['notes']['new_ids'] = explode('~', $customer[$row]['allids']);
$customer['notes']['new_notes'] = explode('~', $customer[$row]['allnotes']);



1:56 pm on Aug 1, 2011 (gmt 0)

10+ Year Member

OK cool, thanks lostdreamer. I will have a go and see if that's the ticket.


9:00 am on Aug 29, 2011 (gmt 0)

10+ Year Member

This worked some minor adjustments... thanks again!

Featured Threads

Hot Threads This Week

Hot Threads This Month