php code to ensure that no more than 2 tracks from any artist are contained

So i have a database imported onto a website, various php files with code that all connect together for the database. The code that is used is for a music website where users can create playlists by selecting songs (that are stored on the database). However I’m new to php and mysql and haven’t got a good grasp on it yet, one of my tasks is to ensure that no more than two tracks from any artist are contained on one playlist. I think i have to write a db query and use a foreach and for loop but i don’t know what to include or how to do this. Any help would be great.

All depends on how the tables are laid out. How are the play lists being stored within the db table? Lots of different ways of accomplishing that.

You may be able to do it inside your query. In SQL, you can count the records found and limit them to a number. But, it does depend on your database layout as Richei stated.

Sponsor our Newsletter | Privacy Policy | Terms of Service