Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.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中编写连接、内部连接mysql查询的自定义方法_Php_Mysql_Codeigniter_Inner Join - Fatal编程技术网

Php 在codeigniter中编写连接、内部连接mysql查询的自定义方法

Php 在codeigniter中编写连接、内部连接mysql查询的自定义方法,php,mysql,codeigniter,inner-join,Php,Mysql,Codeigniter,Inner Join,我有一个从多个表中选择数据的查询。如何在codeigniter中编写其等效代码。 请参见查询: select * from A inner join B on (A.ad_no=B.ad_no) where B.ad_no in (select ad_no from A where $staff!='00:00' and $staff!='0:00') order by B.ctype asc, B.cna

我有一个从多个表中选择数据的查询。如何在codeigniter中编写其等效代码。 请参见查询:

select * 
from A inner join B on (A.ad_no=B.ad_no) 
where  B.ad_no in (select ad_no 
                   from A 
                   where $staff!='00:00' and $staff!='0:00')  
order by B.ctype asc, B.cname asc,B.ad_no asc

我在codeigniter中尝试了一个查询,但加载结果需要更长的时间。

从中获取子查询库

请尝试以下代码

$this->db->select('*')->from('A');
    $this->db->join('b','A.ad_no=B.ad_no','inner');
    $sub = $this->subquery->start_subquery('where_in');
    $sub->select('ad_no')->from('A')->where("staff!='00:00'")->where("staff!='0:00'");
    $this->subquery->end_subquery('B.ad_no', TRUE);
    $this->db->order_by('B.ctype','asc');
    $this->db->order_by('B.cname','asc');
    $this->db->order_by('B.ad_no','asc');
    $query=$this->db->get();

你可以试试下面的方法。我把$sign从staff中删除了

$query = $this->db
    ->select("*")
    ->from("A")
    ->join("B", "A.ad = B.ad_no")
    ->where("B.ad_no in (select ad_no from A where staff!='00:00' and staff!='0:00')",NULL, false)
    ->order_by("B.ctype", "ASC")
    ->order_by("B.cname", "ASC")
    ->order_by("B.ad_no", "ASC")
    ->get();
您将使用以下语句获得生成的输出

echo $this->db
    ->select("*")
    ->from("A")
    ->join("B", "A.ad = B.ad_no")
    ->where("B.ad_no in (select ad_no from A where staff!='00:00' and staff!='0:00')",NULL, false)
    ->order_by("B.ctype", "ASC")
    ->order_by("B.cname", "ASC")
    ->order_by("B.ad_no", "ASC")
    ->get_compiled_select();
$db->query'select*从A.ad_no=B.ad_no中的内部连接B.ad_no从where$staff中选择ad_no!='00:00'和$staff!='0:00'按B.C类型asc、B.cname asc、B.ad_no asc订购'where$staff有什么用!='00:00'和$staff!='“0:00”他们为什么带着美元?