dongzan9069 2015-07-16 12:25
浏览 8
已采纳

发布特定用户的可见性

I'm about to start programming some kind of website which works like this:

User logs in, and if he's a normal user(not an admin) he'll be presented with some posts that relate to his kind of account(Accouns are menaged and given by admin)

What admin does is creates those posts and while creating it he says who will have access to seeing that post (e.g checks a user who will see it , or several users or maybe all users will be able to see it)

My problem is , what kind of tables should i create in my database and with what columns. My first plan was to have ofc: 1) table of users 2) table of posts 3) table of permissions table of permission would have fields ([postID], and then fileds like [user1],[user2]....[userN]) and example row in the table would look like 21|true|true|false|true|....|true| which indicates that those users will be able to see the post. And those fields [userN] could be created dinamically as new users are created I'm asking for an opinion on this kind of db, and ofcourse your idea for doing this db.

  • 写回答

1条回答 默认 最新

  • dongling3243 2015-07-16 12:45
    关注
    create table users
    (   id int not null auto_increment primary key,
        fullName varchar(100) not null
    );
    
    create table posts
    (   id int not null auto_increment primary key,
        postName varchar(200) not null
    );
    
    create table post_user_junction
    (   id int not null auto_increment primary key,
        userId int not null,
        postId int not null,
        UNIQUE (userId,postId),
        -- foreign key (FK) referential integrity:
        FOREIGN KEY (userId) REFERENCES users(id),
        FOREIGN KEY (postId) REFERENCES posts(id)
    );
    
    insert post_user_junction (userId,postId) values (1,1);
    -- ooops, Error 1452, FK violation, user and post do not exist yet
    
    insert users(fullName) values ('a');
    insert posts(postName) values ('a');
    
    -- works:
    insert post_user_junction (userId,postId) values (1,1);
    
    -- do it again, does not work, already there:
    insert post_user_junction (userId,postId) values (1,1);
    

    There you go, you should be out of the gates with the above, to at least start.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题