开发者

Storing user music playlists for a website

开发者 https://www.devze.com 2023-03-06 10:18 出处:网络
I want to make a music playing website where users can save playlists of songs to be regenerated later. I\'m kind of a newbie to sql, but it seems like databases are meant to hold fixed-length variabl

I want to make a music playing website where users can save playlists of songs to be regenerated later. I'm kind of a newbie to sql, but it seems like databases are meant to hold fixed-length variables, whereas a user-generated playlist would be an arbitrary length. There are a couple ways I've thought of to handle this开发者_开发百科:

  • Separate tables (maybe another table for each playlist? )
  • XML

I feel like there's an easy third way I'm missing. I'm doing this in php, but if there's a super easy way using django I'd also be interested.


2 tables:

  1. Playlists. Fields: id | title | owner_id (reference to user.id)
  2. Songs. Fields: id | title | length | playlist_id (reference to playlist.id)


How about this:

Playlists: list_id|title|owner_id
Songs: song_id|title|artist|album|year|length|style|whatevereelseyouwnattoadd
Songs_In_Lists: song_id|list_id

Third table just ties songs to playlists. otherwise there will be a lot of redundancy with song info if song goes to multiple playlists. The primary key for the third table will be on both columns. Same song goes to same list only once, so it works fine.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号