【问题标题】:CodeIgniter retrieving joined columns and non joined one?CodeIgniter 检索加入的列和未加入的列?
【发布时间】:2014-03-28 05:12:02
【问题描述】:

我知道你是这样调用和传递不同表中的列的:

$this->db->select('ut.Username,ct.Title',false); 
$this->db->from('username_table AS ut');
$this->db->join('content_table AS ct', 'ct.UserID = ut.UserID');
$query = $this->db->get('content_table');
return $query->result_array();

但是因为我只选择了用户名和标题,所以我不能从任何一个表中调用其他剩余的列。我该怎么做?

我尝试将 SELECT 更改为(从 content_table 中获取 Body 列的数据):

 $this->db->select('ut.Username,ct.Title','ct.Body',false);

但它没有工作。

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:

    你可以试试这个

    $this->db->select('ut.Username,ct.*',false); 
        $this->db->from('username_table ut');
        $this->db->join('content_table ct', 'ct.UserID = ut.UserID');
        $query = $this->db->get('content_table');
        return $query->result_array();
    

    【讨论】:

      【解决方案2】:

      代替:

      $this->db->select('ut.Username,ct.Title','ct.Body',false);
      

      尝试:

      $this->db->select('ut.Username,ct.Title,ct.Body',false);
      

      【讨论】:

        猜你喜欢
        • 2014-12-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多