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?
在android chatapp中实现规则的最佳方法[关闭]
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- dongzha5934 2017-05-11 18:58关注
You can do the following:
-
To show a logged in user his all chats:
SELECT * FROM chat_user WHERE user_id1 = loggedInUserId OR user_id2 = loggedInUserId LIMIT 10;
whereloggedInUserId
is id of the logged in user. -
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;
whereloggedInUserId
is id of the logged in user andchat_id
is the select chat's id.
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报 -
悬赏问题
- ¥30 这是哪个作者做的宝宝起名网站
- ¥60 版本过低apk如何修改可以兼容新的安卓系统
- ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
- ¥50 有数据,怎么建立模型求影响全要素生产率的因素
- ¥50 有数据,怎么用matlab求全要素生产率
- ¥15 TI的insta-spin例程
- ¥15 完成下列问题完成下列问题
- ¥15 C#算法问题, 不知道怎么处理这个数据的转换
- ¥15 YoloV5 第三方库的版本对照问题
- ¥15 请完成下列相关问题!