Local Hero Posted April 24, 2009 Share Posted April 24, 2009 Lets say I have a table with 1 column having a list of months: Jan, Jan, Feb, Jan, Feb, Feb, Jan, Feb And another column having a list of dates associated with those months: 1,2,5,7,14,12,30,16 It looks like this: Jan | 1 Jan | 2 Feb | 5 Jan | 7 Feb | 14 Feb | 12 Jan | 30 Feb | 16 I want to view the results like this: Jan 1 2 7 30 Feb 5 14 12 16 Here is what I'm working with: <?php $sql="SELECT month, day FROM calendar GROUP BY month"; $sql2="SELECT month, day FROM calendar ORDER BY month"; $result=mysql_query($sql); $result2=mysql_query($sql2); while($rows=mysql_fetch_array($result)){ ?> <table><tr><td> <?php echo( $rows['month'] ); ?> </td></tr><tr><td> <?php while($rows2=mysql_fetch_array($result2)){ echo $rows2['day'] ;?> } ?> </td></tr></table> <?php } ?> I'm getting 2 tables - Jan & Feb, but all the dates go in Jan. I can see why it's doing that. I can't figure out how to get the Feb dates over in the Feb table. Thanks for any suggestions or direction. Quote Link to comment https://forums.phpfreaks.com/topic/155532-seperating-groups-almost-there/ Share on other sites More sharing options...
xtopolis Posted April 25, 2009 Share Posted April 25, 2009 I think by using Group Concat you could achieve a dataset that looks like this: [pre] Month | Days Jan | 1,2,7,30 Feb | 5,14,12,16 [/pre] Perhaps that version would be helpful, since you can split the dates using explode. Be aware of the limitations of group concat cited in the manual however. Quote Link to comment https://forums.phpfreaks.com/topic/155532-seperating-groups-almost-there/#findComment-818822 Share on other sites More sharing options...
fenway Posted April 27, 2009 Share Posted April 27, 2009 Why do you have *two* select statements??? Quote Link to comment https://forums.phpfreaks.com/topic/155532-seperating-groups-almost-there/#findComment-819970 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.