dqzow3859 2017-05-11 18:43
浏览 45
已采纳

在android chatapp中实现规则的最佳方法[关闭]


I'm developing a chat application (android + PHP) and I have the following mysql database:

TABLE User: username (UNIQUE), psw, email (PK), location, user_id (unique), name

TABLE chat_user: id_chat_user, user_id1, user_id2

TABLE chat: id_chat (PK), id_chat_user, user_id, message, timestamp

User_id is generated with the php uuid function and then encrypted in md5.
Now I should handle the roles to make sure that a user needs to read only his chats.
What method can I use?

  • 写回答

1条回答 默认 最新

  • dongzha5934 2017-05-11 18:58
    关注

    You can do the following:

    1. To show a logged in user his all chats:

      SELECT * FROM chat_user WHERE user_id1 = loggedInUserId OR user_id2 = loggedInUserId LIMIT 10; where loggedInUserId is id of the logged in user.

    2. To show a logged in user all messages from one of his chats

      SELECT t2.* FROM chat t1 JOIN chat_user t2 ON (t1.id_chat_user = t2.id_chat_user) WHERE (t1.user_id1 = loggedInUserId OR t2.user_id2 = loggedInUserId) AND t2.id_chat = chat_id ORDER BY timestamp DESC LIMIT 100; where loggedInUserId is id of the logged in user and chat_id is the select chat's id.

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

报告相同问题?

悬赏问题

  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题