pedro84 Posted September 24, 2008 Share Posted September 24, 2008 Hi! I got three tables: musicians, bands and musicians_bands. In musicians and database I'm storing all musicians and bands data. I musicians_bands table I store informations about bands of specifics musicians they were members. Now question. I got following query: $query = mysql_query("SELECT * FROM musicians, bands, musicians_bands where (musicians_bands.id=musicians.id) and (musicians_bands.id=bands.id) group by bands.id"); I returns for me: Artist 1 - Band 1 Artist 2 - Band 2 Artist 1 - Band 3 How to force it to display: Artist 1 - Band 1, Band 3 Artist 2 - Band 2 ? Link to comment https://forums.phpfreaks.com/topic/125654-mysql-query-help-needed/ Share on other sites More sharing options...
.josh Posted September 24, 2008 Share Posted September 24, 2008 You can order by artist in your query and then setup a condition in your results loop to either add a comma and stay on the same line or start a new line when the artist changes. Link to comment https://forums.phpfreaks.com/topic/125654-mysql-query-help-needed/#findComment-649673 Share on other sites More sharing options...
pedro84 Posted September 24, 2008 Author Share Posted September 24, 2008 Any tips how to make it? Link to comment https://forums.phpfreaks.com/topic/125654-mysql-query-help-needed/#findComment-649730 Share on other sites More sharing options...
pedro84 Posted September 24, 2008 Author Share Posted September 24, 2008 Anybody? Link to comment https://forums.phpfreaks.com/topic/125654-mysql-query-help-needed/#findComment-649810 Share on other sites More sharing options...
.josh Posted September 24, 2008 Share Posted September 24, 2008 What kind of tips are you wanting? You seem to already have a query and a method for displaying it. Just change your query to order it by artists instead, and add a condition in your loop that lists the stuff out to make a new line if the currently fetched row's artist changes... Link to comment https://forums.phpfreaks.com/topic/125654-mysql-query-help-needed/#findComment-649889 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.