$this->db->select("sub_courses as courses");
$this->db->from("second_sub_courses");
if(!empty($params['searchTerm']))
{
$this->db->like('courses', $params['searchTerm']);
}
$query1 = $this->db->get_compiled_select();
$this->db->select("course_name as courses");
$this->db->distinct();
$this->db->from("all_courses");
if(!empty($params['searchTerm']))
{
$this->db->like('courses', $params['searchTerm']);
}
$query2 = $this->db->get_compiled_select();
$query = $this->db->query($query1." UNION ".$query2)->result();
$result = ($query->num_rows() > 0)?$query->result_array():FALSE;
return $result;
我正在创建一个自动完成框,由于此查询,该框尚无法使用。在这里,我使用联合使用courses
键属性在单个列中获取两个表数据,但是现在它抛出一个错误,正如我在问题中提到的那样,我对此错误一无所知。如何解决此错误?请帮助我。
谢谢
答案 0 :(得分:0)
我认为您应该删除->result()
,请检查以下代码。
$this->db->select("sub_courses as courses");
$this->db->from("second_sub_courses");
if(!empty($params['searchTerm']))
{
$this->db->like('courses', $params['searchTerm']);
}
$query1 = $this->db->get_compiled_select();
$this->db->select("course_name as courses");
$this->db->distinct();
$this->db->from("all_courses");
if(!empty($params['searchTerm']))
{
$this->db->like('courses', $params['searchTerm']);
}
$query2 = $this->db->get_compiled_select();
$query = $this->db->query($query1." UNION ".$query2);
$result = ($query->num_rows() > 0)?$query->result_array():FALSE;
return $result;
答案 1 :(得分:0)
您应该删除->result()
$query = $this->db->query($query1." UNION ".$query2);