【发布时间】:2016-01-02 18:43:18
【问题描述】:
我正在使用 CodeIgniter 开发一个私人消息应用程序。
我有 3 张桌子:
- 对话
- conversations_messages
- conversations_members。
我正在尝试通过匹配对话ids 来加入表格,并为已登录的用户获取所有消息。
这是标准的 sql 查询
SELECT
'conversations','conversation_id',
'conversations','conversation_subject',
MAX('conversations_messages','message_date') AS 'conversation_last_reply'
FROM 'conversations'
LEFT JOIN 'conversations_messages' ON 'conversations'.'conversation_id' = 'conversations_messages'.'conversation_id'
INNER JOIN 'conversations_members' ON 'conversations'.'conversation_id' = 'conversations_members'.'conversation_id'
WHERE 'conversations_members', 'user_id' = $sender_id
AND 'conversations_members','conversation_deleted' = 0
GROUP BY 'conversations'.'conversation_id'
ORDER BY 'conversation_last_reply' DESC";
这是一个很大的查询,因此;我不确定如何将其转换为 CodeIgniter 活动记录,或者只是让它与框架一起运行。
任何更正也将不胜感激。
【问题讨论】:
-
在 phpmyadmin 中尝试查询,看看发生了什么错误。我注意到一件事..您在 where 条件下使用了“'conversations_members', 'user_id' = $sender_id” 而不是 'conversations_members.user_id' = $sender_id。
-
谢谢....我用过它,效果很好
-
如果觉得有用,请点赞。
标签: php mysql codeigniter