Php 如何将sql union转换为codeigniter方式
如何使用PHP CodeIgniter框架进行联合查询执行此查询时出现错误Php 如何将sql union转换为codeigniter方式,php,sql,codeigniter,search,union,Php,Sql,Codeigniter,Search,Union,如何使用PHP CodeIgniter框架进行联合查询执行此查询时出现错误 Every derived table must have its own alias 模型 如何更改它您只需为每个表添加查询,并使用下面的union连接它们,就可以做到这一点 $this->db->select('ID,section,title,img,year,lastupdateon AS ondate,`moves` AS dept,STATUS'); $this->db->from(
Every derived table must have its own alias
模型
如何更改它您只需为每个表添加查询,并使用下面的union连接它们,就可以做到这一点
$this->db->select('ID,section,title,img,year,lastupdateon AS ondate,`moves` AS dept,STATUS');
$this->db->from('movies');
$query1 = $this->db->get_compiled_select();
$this->db->select('ID,section,title,img,year,lastupdateon AS ondate,`kid` AS dept,STATUS');
$this->db->from('kids');
$query2 = $this->db->get_compiled_select();
$this->db->select('ID,views,title,img,version AS year,ondate,`software` AS dept,STATUS');
$this->db->from('soft');
$query3 = $this->db->get_compiled_select();
$this->db->select('ID,section,title,img,'PC Game' AS year,ondate,`game` AS dept,STATUS');
$this->db->from('games');
$query4 = $this->db->get_compiled_select();
$this->db->select('ID,season,title,img,type AS year,lastupdatedon AS ondate,`tvshow` AS dept,STATUS');
$this->db->from('tvshows');
$query5 = $this->db->get_compiled_select();
$this->db->like('title', $title , 'after');
$this->db->order_by('ondate', 'DESC');
$this->db->limit(10);
$query = $this->db->query($query1 . ' UNION ' . $query2. ' UNION ' . $query3. ' UNION ' . $query4. ' UNION ' . $query5);
return $this->db->get($query)->result();
您只需为每个表添加查询,并使用下面的union连接它们,就可以做到这一点
$this->db->select('ID,section,title,img,year,lastupdateon AS ondate,`moves` AS dept,STATUS');
$this->db->from('movies');
$query1 = $this->db->get_compiled_select();
$this->db->select('ID,section,title,img,year,lastupdateon AS ondate,`kid` AS dept,STATUS');
$this->db->from('kids');
$query2 = $this->db->get_compiled_select();
$this->db->select('ID,views,title,img,version AS year,ondate,`software` AS dept,STATUS');
$this->db->from('soft');
$query3 = $this->db->get_compiled_select();
$this->db->select('ID,section,title,img,'PC Game' AS year,ondate,`game` AS dept,STATUS');
$this->db->from('games');
$query4 = $this->db->get_compiled_select();
$this->db->select('ID,season,title,img,type AS year,lastupdatedon AS ondate,`tvshow` AS dept,STATUS');
$this->db->from('tvshows');
$query5 = $this->db->get_compiled_select();
$this->db->like('title', $title , 'after');
$this->db->order_by('ondate', 'DESC');
$this->db->limit(10);
$query = $this->db->query($query1 . ' UNION ' . $query2. ' UNION ' . $query3. ' UNION ' . $query4. ' UNION ' . $query5);
return $this->db->get($query)->result();
评论不用于扩展讨论;对话已经结束,请看一看。我认为它的修正得到的结果来自于最后的发帖日期,但不是来自于搜索条件,现在工作得很好,谢谢,建议不需要进一步讨论;对话已经结束,请看一看。我认为它可以从上一次发布的日期得到结果,但不能从搜索条件中得到完美的结果,谢谢