开发者

Codeigniter Get Values from two tables

I am trying to list some data from two tables. I am trying to do this: From table users I am trying to list from table "firm_info" firms added for the 开发者_高级运维current user. The idea:

John

  • firm 1
  • firm 2
  • firm 3

Michael

  • no firms listed

Joe

  • firm 1
  • firm 2


what you need to is a left join on users and firms table.

In this case your left table would be users. Hope you find the above link helpful


It's all on the documentation. http://codeigniter.com/user_guide/database/active_record.html Search for the function $this->db->join(); and btw i just answered the same question like 10 minutes again. Use the stackoverflow search function next time.

From codeigniter user_guide

$this->db->join();

Permits you to write the JOIN portion of your query:

$this->db->select('*');
$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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜