【发布时间】:2016-01-03 00:03:08
【问题描述】:
我正在开发一个私人消息系统,我有 3 个表格,看起来像这样
对话 对话主题
CONVERSATIONS_MEMBERS 对话ID|用户ID|对话最后视图|对话删除
CONVERSATIONS_MESSAGES message_id|conversation_id|user_id|message_date|message_text
表结构是不言自明的。但我想要的是加入所有表格,选择并在收件箱页面上显示消息。
我已经尝试过这个查询,但我不断收到错误。我是 sql 的新手;我只能做简单的事情。
$this->db->select('conversations, conversation_id,conversations, conversation_subject');
$this->db->select_max('conversations_messages.message_date', 'conversation_last_reply');
$this->db->from('conversations');
$this->db->join('conversations_messages','conversations.id=conversations_messages.conversation_id','left');
$this->db->join('conversations_members','conversations.id= conversations_members.conversation_id','inner');
$this->db->where('conversations_members.user_id',$sender_id);
$this->db->where('conversations_members.conversation_deleted','0');
$this->db->group_by('conversations.conversation_id');
$this->db->order_by('conversation_last_reply');
// Get the results from db
$query = $this->db->get();
// Result array contains the records selected
$result_array = $query->result_array();
【问题讨论】:
-
$this->db->select();试试这个
标签: php mysql codeigniter