php - Structuring a MySQL table where the PLAYLIST table refers to multiple VIDEO id integers and a USER table id -


i want retrieve 1 complete object videoplaylist contains complete user object , video objects related it.

i understand need use left join merge them, cant understand how should setup playlist table , how query when comes multiple video id's.

this current database eer diagram: original eer diagram of database tables

should create many many relationship between playlist , video? should somehow store video id's in playlist table? , how able query it?

this i'm stuck:

select * videoplaylist left join user left join video on user.id = playlist.user_id , videos.... 

ps. won't querying 1 playlist @ time, need display them in list format.

yes, should create many-to-many relationship between video , playlist table if want 1 video added multiple playlists , vice versa.

so many-to-many relationship table combination of playlist_id , video_id primary key.

playlist_has_video ------------------ playlist_id video_id 

if want able add video more once playlist have create id col in table too. id primary key.

playlist_has_video ------------------ id playlist_id video_id 

when want enable user sort playlist think adding col order_id n-to-m table.

playlist_has_video ------------------ id playlist_id video_id order_id 

now lets see select queries (i refer last design, id + order_id)

retrieving videos playlist:

select video.* playlist_has_video phv left join video on phv.video_id = video.id phv.playlist_id = :playlist_id order order_id asc; 

retrieving playlists video in:

select playlist.* playlist_has_video phv left join playlist on phv.playlist_id = playlist.id phv.video_id = :video_id; 

you have alter video - table if use approach (make sure remove playlist_id)

video --------- id title description user_id transcript_id created updated 

Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -