Jump to content

Group data in rows


Stevenn

Recommended Posts

I have data

 

 

Name, Year, Month, Amount
==
A, 2012, nov, 14
A, 2012, dec, 48
A, 2012, jan, 8
B, 2011, feb, 17
B, 2011, aug, 10
(...)

 

 

How is it possible to group the names, so the output will be

 

Name, Feb2011, Aug2011, Jan2012, Nov2012, Dec2012
==
A, 0, 0, 8, 14, 48
B, 17, 10, 0, 0, 0

 

I have really no idea what function to look for.

Link to comment
https://forums.phpfreaks.com/topic/274695-group-data-in-rows/
Share on other sites

You need to use some logic in PHP. Where is the data coming from?

Basically you need to order them by the parent (In your case, A and B ) and then keep track of which one you're printing when you output.

I wrote an article about this on my site. It's using MySQL but the logic is the same no matter where your data comes from.

http://thewebmason.c...t-child-lists/

 

Just saw you posted this in MySQL so I'm going to assume it's a MySQL Database ;)

Link to comment
https://forums.phpfreaks.com/topic/274695-group-data-in-rows/#findComment-1413467
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.