Jump to content

Join Relational tables with 'GROUP_CONCAT"?


justlikethat

Recommended Posts

Hello, thanks to a lot of resources and some helpful people along the way, I was able to create a relational database for the purpose of showing events - however I am stuck now.

 

My XML query searches for events.

 

The events table has a foreign key linking to the venues table, which links to the venue_types and locations tables. Some very simple one-to-many relationship I did.

 

-----------------------------------------------------------

What my problem is now, is that each event also has multiple music genres. Because of that, I created two additional tables.

 

music_styles and events_music_styles

 

The music_styles table contains an ID and the corresponding name of that musical style attached to that ID.

 

The events_music_styles table contains the ID of the events table and the music_styles table.

 

This way, if an event has two musical genres, the table in events_music_styles would look something like this:

 

EVENT_ID MUSIC_STYLE_ID

1 2

1 4

 

That would say that event 1 has music styles 2 and 4.

--------------------------------------------------------

 

 

What I want to do is link this events_music_styles table to the events table, and use GROUP_CONCAT to combine the two rows returned by events into one.

 

So if it looks like this:

 

Event_id event_name music_style_id

1 event 1 2

1 event 1 4

 

I want it to turn into this:

 

Event_id event_name music_style_name

1 event 1 latino, reggae

 

 

-----------------------------------------------------------

I made a small database mockup and this is what it looks like:

 

959wJ.jpg

 

 

Right now the events_music_styles table isn't linked to my events table so the xml result looks like this:

 

8aIsA.jpg

 

And the code behind it looks like this:

Code:

 

$query = 'SELECT events.*, venues.*, locations.*'.
       'FROM events '.
       'INNER JOIN venues ON(events.VENUE_LOCATION = venues.ID)'.
       'INNER JOIN locations ON(events.VENUE_LOCATION = locations.ID)';

 

 

 

Code:

 

  echo '<marker ';
  echo 'id="' . parseToXML($row['ID']) . '" ';
  echo 'date="' . $row['EVENT_DATE'] . '" ';
  echo 'event_name="' . $row['EVENT_NAME'] . '" ';
  echo 'location="' . $row['LOCATION'] . '" ';
  echo 'place="' . $row['VENUE_NAME'] . '" ';
  echo '/>';

 

 

 

 

I'm doing tons of reading on this subject so hopefully I won't be too much clueless if someone tries to give me any tips. Thanks everyone and sorry for such a long post Thanks for your time as well ! )))

Link to comment
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.