SimonKA Posted June 24, 2020 Share Posted June 24, 2020 Hello, My database is organized in two tables, called content and additional_info. The structure is as followed: content ID | title | text ---------------------- 1 | Title A | Text A 2 | Title B | Text B additional_info ID | idContent | info ----------------------- 1 | 1 | Info A1 1 | 1 | Info A2 1 | 2 | Info B1 1 | 2 | Info B2 Now I like to show my users a HTML table such as Result (desired): Title | Information --------------------------- Title A | Info A1, Info A2 Title B | Info B1, Info B2 Selecting the data with a JOIN_ SELECT c.title, i.info FROM Content c JOIN additional_info a ON a.idContent = c.ID returns a table with four rows: Title | Information ---------------------- Title A | Info A1 Title A | Info A2 Title B | Info B1 Title B | Info B2 My current solution is to check the value of the title. If there is no chance, I add the information, if there is a change, I print the new title in a new row (<tr>). But maybe there is also a more dynamic way or a solution “imploding” the information….? Thank you, Simon Quote Link to comment https://forums.phpfreaks.com/topic/310995-join-with-more-than-one-result/ Share on other sites More sharing options...
kicken Posted June 24, 2020 Share Posted June 24, 2020 Have a look into GROUP BY and GROUP_CONCAT Quote Link to comment https://forums.phpfreaks.com/topic/310995-join-with-more-than-one-result/#findComment-1579130 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.