Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.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)。现在,我想查找并显示所有重复的护照号码及其与表1中表2中的护照号码匹配的数据 例如: table1 : id | name | passport_number | test_date 1 | jane doe | a123456 | 1-Jan-2017 2 | jane doe | a123456 | 2-Jan-2017 3 | jane doe | a123456 |

我有一份带有护照号码的候选人主记录(表1),另一份带有候选人护照号码的记录(表2)。现在,我想查找并显示所有重复的护照号码及其与表1中表2中的护照号码匹配的数据

例如:

    table1 :
    id | name | passport_number | test_date
    1 | jane doe | a123456 | 1-Jan-2017
    2 | jane doe | a123456 | 2-Jan-2017
    3 | jane doe | a123456 | 3-Jan-2017
    4 | doe jane | b123456 | 1-Jan-2017
    5 | doe jane | b123456 | 2-Jan-2017
    6 | name | d123456 | 5-Jan-2017

    table2:
    id | passport_number | test_date
    1 |  a123456 | 1-Jan-2017
    2 |  c123456 | 4-Jan-2017
    3 |  a123456 | 2-Jan-2017
    4 |  b123456 | 1-Jan-2017
    5 |  b123456 | 2-Jan-2017

Results should be:
 id | name | passport_number | test_date
    1 | jane doe | a123456 | 1-Jan-2017
    2 | jane doe | a123456 | 2-Jan-2017
    3 | jane doe | a123456 | 3-Jan-2017
    4 | doe jane | b123456 | 1-Jan-2017
    5 | doe jane | b123456 | 2-Jan-2017

现在,我想从表2中获得所有护照号码的数据(仅当候选人出现在表1中的两个测试日期时),将其与表1护照号码进行比较,并查看该候选人在以前的日期进行了多少次测试。它应该显示passport的所有重复条目,而不仅仅是group_by或count的一个条目。

您的查询可能是这样的

$this->db->select('*');
$this->db->from('table1');
$this->db->join('table2', 'table1.passport_number  = table2.passport_number ', 'left'); 
$query = $this->db->get();
return $query->result();

谢谢Elena,这一个对我有效,但有一个小问题,当我使用group_by(“passport_number”)时,它会把结果弄乱,并且它不会对相同的passport号码进行分组。有什么想法吗?如果你使用我的查询,那么应该是$this->db->group_by(“t1.passport_number”);-它返回2行(id=1和id=4)。
$this->db->select("t1.*", FALSE);
$this->db->from("table1 t1, table2 t2");
$this->db->where("t1.passport_number", "t2.passport_number", FALSE);
$this->db->group_by("t1.id");
$result = $this->db->get();