misc00500 Posted May 17, 2007 Share Posted May 17, 2007 this is probably a stupid question to ask but, I was wondering if there was a way to turn attach rows of result set from a subselect into column data of the outer select. IE. turn this: prop_id | extra_photo | caption ----------------------------------------------- 123 | 1.jpg | 123 spring 123 | 2.jpg | 123 fairfax 124 | 3.jpg | 123 freelance into this: property_id | address | city | caption_1 | caption_2 | caption_3 --------------------------------------------------------------------------- 123 | blah | blah | 123 spring | 123 fairfax | NULL 124 | blah | blah | 123 freelance | NULL | NULL Quote Link to comment https://forums.phpfreaks.com/topic/51794-turn-rows-data-into-columns-data/ Share on other sites More sharing options...
bubblegum.anarchy Posted May 17, 2007 Share Posted May 17, 2007 Columns can not be created dynamically. A group_concat can group all the captions into one column and add a seperator as well... have a look at the group_concat information here: http://dev.mysql.com/doc/refman/4.1/en/group-by-functions.html Quote Link to comment https://forums.phpfreaks.com/topic/51794-turn-rows-data-into-columns-data/#findComment-255228 Share on other sites More sharing options...
misc00500 Posted May 17, 2007 Author Share Posted May 17, 2007 thanks alot bubblegum. boy, for someone who's name is bubblegum, you sure do know alot. But I was hoping to avoid using group_concat, as I'll have to use php string functions to extract each individual captions out. Quote Link to comment https://forums.phpfreaks.com/topic/51794-turn-rows-data-into-columns-data/#findComment-255231 Share on other sites More sharing options...
bubblegum.anarchy Posted May 17, 2007 Share Posted May 17, 2007 Only one php function would be required.. with using a newline separator in the group_concat... $caption = explode("\n", $record['caption']); Quote Link to comment https://forums.phpfreaks.com/topic/51794-turn-rows-data-into-columns-data/#findComment-255232 Share on other sites More sharing options...
misc00500 Posted May 17, 2007 Author Share Posted May 17, 2007 hm. that's true. damn.. I might have to rewrite my table structure... thanks alot bubble Quote Link to comment https://forums.phpfreaks.com/topic/51794-turn-rows-data-into-columns-data/#findComment-255240 Share on other sites More sharing options...
fenway Posted May 18, 2007 Share Posted May 18, 2007 Columns can not be created dynamically. A group_concat can group all the captions into one column and add a seperator as well... have a look at the group_concat information here: http://dev.mysql.com/doc/refman/4.1/en/group-by-functions.html Yeah, but in this case, you could "JOIN" these two selects based on the ID column. Quote Link to comment https://forums.phpfreaks.com/topic/51794-turn-rows-data-into-columns-data/#findComment-256674 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.