Mysql – SQL Database, how to set up users saving favorite songs

database-designMySQLPHP

I'm setting up a web page and database for SQL practice where a bunch of songs will be saved in one database table, and there will be a table of 'users' (all just be testing however…) of the site. I wanted to make a feature of allowing users to build a list of songs they like from those in the database. But I'm unsure how best to keep track of the liked songs of each user.

As far as I know there isn't an array like attribute to add to the users table to hold their linked songs list so the only things I can think to do are:

  1. Create a table for each user upon account registration to hold their liked songs.

  2. Create a mass table holding all songs liked by users, with an attribute of the liking user and then to display their liked songs, pull all from that table that have their name.

Are either of these sufficient? Is there some better way to this?

Best Answer

I would pull down MusicBrainz's recording table and simply link it to your users with either a m2m table, or as an array of their favorite recordings (1:n). Depending on whether or not you're querying on the data or just displaying it for the user.