homepage Welcome to WebmasterWorld Guest from 54.166.111.111
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Query with Group Concat
Pico_Train




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

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

SELECT *,
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
[lastname]=>customerlastname
etc...
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?

Thanks!

 

lostdreamer




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

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']);


To


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


Regards,
LostDreamer

Pico_Train




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

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

Pico_Train




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

This worked some minor adjustments... thanks again!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved