我正在使用codeigniter,我有一个函数用于搜索mysql表中的多个列,这些列无效。我需要搜索限制因为我需要对搜索结果进行分页。
例如,我的mysql数据库中的3个表是phones
,articles
,solutions
,搜索字符串是sony
。我的phones.name
和articles.title
以及solutions.title
的名称为sony
。
我现有的功能是
public function get_search_res($search_str = null,$limit_start = null, $limit_end = null)
{
$this->db->select('phones.name , phones.id');
$this->db->select('solutions.title as s_title');
$this->db->select('articles.title as a_title');
$this->db->from('phones , soltions , articles');
$this->db->like('phones.name', $search_str);
$this->db->or_like('articles.title',$search_str);
$this->db->or_like('solutions.title',$search_str);
$this->db->limit($limit_start, $limit_end);
$q = $this->db->get();
$res = $q->result_array();
return $res;
}
此函数仅获取内容形式solutions
表,但无法从另外两个具有限制的表中获取所有内容。
还有其他办法吗?
答案 0 :(得分:0)
您尝试做的事情是不可能的 不使用多个表的查询。
您想要搜索3个表,因此您必须分别查询每个表。
根据查询结果集的LIMIT,从每个表中获取COUNT个结果。