Jump to content

fixing up this query


TheTitans

Recommended Posts

On my web page, I want to display a list of CDs that are associated with each article, and the songs that are associated with each CD.

 

To do this, I have three tables:

1. A table for the CDs

2. A table that has all the songs

3. A table that associates each CD with its song

 

Table cds has columns: id, article_id, name

Table songs has columns: id, name, lyrics

Table cd_songs has columns: id, cd_id, song_id

 

Now I have a the query that gets the CDs that are associated with each article.

$sql = "SELECT cds.id, cds.name, DATE_FORMAT(cds.release_date, '%M %e, %Y') AS formatted_date FROM cds WHERE cds.article_id = '" . $this->id . "'";

 

But I don't know how to modify the query so that it can also select all the songs for each CD. I'm not sure how to use the JOINs with this, so maybe someone can give me some assistance.

Link to comment
https://forums.phpfreaks.com/topic/163055-fixing-up-this-query/
Share on other sites

Yes, JOINs would be required... what kind of output are you looking for?

 

The web page would show a list of the CDs. Under each CD would be the list of songs (just the name of the songs) that are associated with it. Each song would have a link to its own page to where the lyrics would be displayed. I know how to display the list of CDs. I just need some help with displaying the song names for each CD.

Link to comment
https://forums.phpfreaks.com/topic/163055-fixing-up-this-query/#findComment-861010
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.