duanhan5388 2016-09-13 01:13
浏览 37

MySQL查询检查登录用户是否有权访问内容? (内容属于用户注册的类)

I have a theoretical issue, that I need to translate it to a database query in MySQL.

I have students that can be enrolled into a class. Each class have some class lectures (content). Only students enrolled in the class should be able to access the lectures assigned to that class. Each lecture could be assigned to N classes.

I have several tables:

USERS table with the userID field.

CONTENT table with contentID field.

CLASS table with the classID field.

USERS-CLASSES table with the userID and the classID fields

CONTENTS-CLASSES table with the classID and contentID fields.

I have no idea on how the query should actually be formulated to check that the user ID of the logged in user is connected with the classID of the class to which the lecture that the user wants to read belongs to (the content).

Any clue will be greatly appreciated.

  • 写回答

1条回答 默认 最新

  • drqja5919276 2016-09-13 01:23
    关注

    This can be completed with a simple INNER JOIN

    SELECT 1 FROM USERS-CLASSES uc
    INNER JOIN CONTENTS-CLASSES cc ON cc.classID = uc.classID
    WHERE uc.userID = {userID}
    

    If the query returns 1, they're authorized to view that content.

    If you want to know for a userID AND classID, simply add it to your where.

    SELECT 1 FROM USERS-CLASSES uc
    INNER JOIN CONTENTS-CLASSES cc ON cc.classID = uc.classID
    WHERE uc.userID = {userID}
    AND uc.classID = {classID}
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题