2015-12-21 51 views
2

我使用datatables来显示旅游的重要细节,但是当我使用select查询时显示fk整数值,而我想要那里在tour_standered表中的类型名称通过codeigniter中的数据表显示fk而不是数值的名称

我的表图像如下

customize tours

tour standard

型号功能

public function cust_tour_primary_data(){ 
    $this->db->select(''); 
    $this->db->from('customized_tours'); 
    $this->db->join('tour_standered', 'tour_standered.std_id =customized_tours.std_type','left'); 
    $res=$this->db->get(); 
    //return $res->result(); 
    print_r($res->result()); 
    echo $this->db->last_query(); 
} 

通过以上功能,我能够得到FK的名字,但我不希望的tour_standered像创建,删除等 等领域,我想其他FK值做同样的。通过这样做,查询结果会太长,有点混乱,我也不知道如何做多重连接。

+1

只是在选择查询中添加你需要从表中获得什么东西 –

+0

thx它的工作原理,但在所有连接表中必须有所有唯一的名称,我得到了错误id模糊不清,所以我改变了名称现在它工作正常 –

+0

使用别名为相同的名称列@ shivakumar –

回答

0

您可以指定在选择方法需要的申请名称,如:

$this->db->select('title, content, date'); 

将只选择标题,从表中的内容和日期(参见:Codeigniter active record

你可以加入多个表,因为你已经为第一个表做了同样的方式,如:

$this->db->select('*'); 
$this->db->from('blogs'); 
$this->db->join('comments', 'comments.id = blogs.id'); 
$this->db->join('user', 'user.id = blogs.user_id'); 

上述查询连接“博客”,“意见”和“用户”表。

+0

雅它适用于我。请帮助理解左连接和简单连接。 –

相关问题