【问题标题】:Searching multple mysql tables with limit using Codeigniter使用 Codeigniter 搜索具有限制的多个 mysql 表
【发布时间】:2013-11-10 16:38:14
【问题描述】:

我正在使用 codeigniter,并且我有一个在 mysql 表中搜索多个列的功能,但它不起作用。我需要限制搜索,因为我需要对搜索结果进行分页。

例如,我的mysql数据库中的3个表是phonesarticlessolutions,搜索字符串是sony。我有phones.namearticles.titlesolutions.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 表的内容,但无法获取另外两个有限制的表的所有内容。

还有其他方法吗?

【问题讨论】:

    标签: php mysql codeigniter


    【解决方案1】:

    您尝试做的事情是不可能的。
    不使用多表查询来做到这一点。

    您要搜索 3 个表,因此您必须分别查询每个表。

    根据您在结果集查询中的 LIMIT 从每个表中获取 COUNT 个结果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-01
      • 1970-01-01
      • 2013-01-20
      • 2014-12-03
      相关资源
      最近更新 更多