我正在使用代码点火器,我有一个在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
内容表单,但无法从另外两个具有限制的表中获取所有内容。
还有其他方法可以做到这一点吗?
你尝试做的事情是不可能的。
使用多个表的查询不用于执行此操作。
您要搜索 3 个表,因此必须分别查询每个表。
从每个表中获取 COUNT 结果,以便在查询结果集时根据 LIMIT 进行。