php - MySQL query that checks that the logged in user has access to the content? (where the content belongs to a class where the user is enrolled in) -


i have theoretical issue, need translate database query in mysql.

i have students can enrolled class. each class have class lectures (content). only students enrolled in class should able access lectures assigned class. each lecture assigned n classes.

i have several tables:

users table userid field.

content table contentid field.

class table classid field.

users-classes table userid , classid fields

contents-classes table classid , contentid fields.

i have no idea on how query should formulated check user id of logged in user connected classid of class lecture user wants read belongs (the content).

any clue appreciated.

this can completed simple inner join

select 1 users-classes uc inner join contents-classes cc on cc.classid = uc.classid uc.userid = {userid} 

if query returns 1, they're authorized view content.

if want know userid and classid, add where.

select 1 users-classes uc inner join contents-classes cc on cc.classid = uc.classid uc.userid = {userid} , uc.classid = {classid} 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -