【问题标题】:selecting from three tables in codeigniter从 codeigniter 中的三个表中选择
【发布时间】: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


【解决方案1】:

您的选择方法有误。问题是您正在使用 (,) 用于绑定它应该与 (.) 一起使用

修改后的查询:

$this->db->select('conversations.conversation_id,conversations.conversation_subject');

我改变了什么:

替换这个:

'conversations, conversation_id'

与:

'conversations.conversation_id'

【讨论】:

  • 我早些时候发现了这一点。你也没有发现下面的一些错误......但我要把这个给你!谢谢
猜你喜欢
  • 1970-01-01
  • 2011-02-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-29
  • 1970-01-01
相关资源
最近更新 更多