我正在制作一个私信系统,我有 3个表,看起来像这样
对话 conversation_id | conversation_subject
CONVERSATIONS_MEMBERS conversation_id | user_id | conversation_last_view | conversation_deleted
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();
答案 0 :(得分:0)
您的select方法有错误。问题是你正在使用 (,)用于绑定它应该与(。)
一起使用修改后的查询:
$this->db->select('conversations.conversation_id,conversations.conversation_subject');
我改变了什么:
替换为:
'conversations, conversation_id'
。通过强>
'conversations.conversation_id'