codeigniter:从多个表中选择 [英] Codeigniter: Select from multiple tables

查看:170
本文介绍了codeigniter:从多个表中选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从两个或多个表中选择行?

我设置默认字段的形式,我需要从两个表中值...

我目前的code读取:

  $这个 - > CI-> DB->选择(*);
    $这 - > Cl  - > DB-肽从('user_profiles');
    $这 - > Cl  - > DB-化合物其中('USER_ID',$ ID);
    $ USER = $这个 - > CI-> DB->获得();
    $ USER = $用户自> row_array();
    $这个 - > CI-> validation-> set_default_value($用户);
 

解决方案

用户指南中的例子应该说明这一点:

  $这个 - > DB->选择(*); //<  - 从未有任何理由来写这条线!
$这个 - > DB-肽从('博客');
$这个 - > DB->加入('意见','comments.id = blogs.id');

$查询= $这个 - > DB->获得();

//生成:
// SELECT * FROM博客
//加入关于comments.id = blogs.id评论
 

全看在活动记录页面的用户指南中。

How can I select rows from two or more tables?

I'm setting default fields for a form, and I need values from two tables...

My current code reads:

    $this->CI->db->select('*');
    $this->CI->db->from('user_profiles');
    $this->CI->db->where('user_id' , $id);
    $user = $this->CI->db->get();
    $user = $user->row_array();
    $this->CI->validation->set_default_value($user);

解决方案

The example in the User Guide should explain this:

$this->db->select('*'); // <-- There is never any reason to write this line!
$this->db->from('blogs');
$this->db->join('comments', 'comments.id = blogs.id');

$query = $this->db->get();

// Produces:
// SELECT * FROM blogs
// JOIN comments ON comments.id = blogs.id

See the whole thing under Active Record page in the User Guide.

这篇关于codeigniter:从多个表中选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆