Stevenn Posted February 19, 2013 Share Posted February 19, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/274695-group-data-in-rows/ Share on other sites More sharing options...
Jessica Posted February 19, 2013 Share Posted February 19, 2013 (edited) 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 Edited February 19, 2013 by Jessica Quote Link to comment https://forums.phpfreaks.com/topic/274695-group-data-in-rows/#findComment-1413467 Share on other sites More sharing options...
Barand Posted February 19, 2013 Share Posted February 19, 2013 By using month names instead of month numbers you have painted yourself into a corner when it comes to sorting the dates. Apr, Aug, Feb and Dec come before Jan Quote Link to comment https://forums.phpfreaks.com/topic/274695-group-data-in-rows/#findComment-1413522 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.