Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter从两个表中获取值_Php_Mysql_Codeigniter - Fatal编程技术网

Php Codeigniter从两个表中获取值

Php Codeigniter从两个表中获取值,php,mysql,codeigniter,Php,Mysql,Codeigniter,我试图列出两个表中的一些数据。我正在尝试这样做: 从表用户中,我试图从表中列出为当前用户添加的公司信息。 这个想法: 约翰 公司1 公司2 公司3 迈克尔 没有上市公司 乔 公司1 公司2 你需要的是一个关于用户和公司的表格 在这种情况下,您的左表将是users。希望以上链接对您有所帮助文档中都有。 搜索函数$this->db->join;顺便说一句,我又回答了同样的问题,大概10分钟。下次使用stackoverflow搜索功能 来自codeigniter用户指南 $this->db->join

我试图列出两个表中的一些数据。我正在尝试这样做: 从表用户中,我试图从表中列出为当前用户添加的公司信息。 这个想法:

约翰 公司1 公司2 公司3 迈克尔 没有上市公司 乔 公司1 公司2 你需要的是一个关于用户和公司的表格


在这种情况下,您的左表将是users。希望以上链接对您有所帮助

文档中都有。 搜索函数$this->db->join;顺便说一句,我又回答了同样的问题,大概10分钟。下次使用stackoverflow搜索功能

来自codeigniter用户指南

$this->db->join


什么请解释一下。使用简短的句子。我试图列出表用户中的所有用户,并列出为该用户添加的表公司信息中的所有公司。我尝试使用join,但问题是,如果没有为该用户添加公司,则该用户不会显示在表中try$this->db->select'*'$这->数据库->来自“博客”$这->数据库->加入'comments','comments.id=blogs.id','left'$query=$this->db->get;注意在$this->db->joinyes添加的'left',我使用了left join语句,但是如果为用户添加了两个公司,它会添加另一行,比如:user1-firm1 user1-firm2我需要它:user1-firm1-firm2我认为应该有另一个循环来为用户显示公司,但是我不知道如何在这个循环中创建循环,那么您还必须添加$this->db->group\u by'user\u id;在$this->db->get之前;
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