Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/310995-join-with-more-than-one-result/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.