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