从表单中获取特定单词后。我想从数据库中的多个表中获得这样的结果。
function search(){
$search = $this->input->post('searchword');
$this->db->select('articles.title, articles.post');
$this->db->select('files.name, files.desc');
$this->db->select('news.title, news.post');
$this->db->select('projects.title, projects.desc');
$this->db->from('articles, files, news, projects');
// I think problem is here
$like = array('articles.title' => $search,'articles.post' => $search,
'files.name' => $search,'files.desc' => $search,
'news.title' => $search,'news.post' => $search,
'projects.title' => $search, 'projects.desc' => $search);
$this->db->like($like);
return $this->db->get();
}
答案 0 :(得分:1)
我总是会用连接创建一个合适的sql语句,然后执行它。
$query = $this->db->query("BUILD A PROPERLY JOINED QUERY!");
如果你自己无法做到这一点......在PHPMyAdmin或MySQL Workbench中构建查询,并确保得到你期望的结果。
另外,虽然我不是CI的Active Record的粉丝,但看看这篇文章可能会调整它正在创建的连接-http://codeigniter.com/forums/viewthread/93198/