【发布时间】:2016-11-04 12:46:23
【问题描述】:
这是我的表格,我需要使用 codeigniter 创建一个搜索功能,该功能将显示包含我的关键字的项目列表,按匹配关键字的最多数量和添加的最新日期排序。
例如。提交的两个关键字都是yes,test
messages table
id | title | msg |date
---+-----------+-------------------+--------
1 | test1 | yes | 2016-06-01 // 2 match keywords
2 | yes1 | no | 2016-06-02 // 1 match keywords
3 | test2 | no | 2016-06-03 // 1 match keywords
4 | yes2 | yes yes yes | 2016-06-04 // 4 match keywords
5 | yesyes3 | yes yes yes yes | 2016-06-05 // 6 match keywords
现在它会显示预期的输出:
array (
[0] => array (
[id] => 5
[title] => yesyes3
[msg] => yes yes yes yes
[date] => 2016-06-05
[match] => 6
)
[1] => array (
[id] => 4
[title] => yes2
[msg] => yes yes yes
[date] => 2016-06-04
[match] => 4
)
[2] => array (
[id] => 1
[title] => test1
[msg] => yes
[date] => 2016-06-01
[match] => 2
)
[3] => array (
[id] => 3
[title] => test2
[msg] => no
[date] => 2016-06-03
[match] => 1
)
[4] => array (
[id] => 2
[title] => yes1
[msg] => no
[date] => 2016-06-02
[match] => 1
)
)
目前这里是我当前的代码,我不确定这些如何使这个搜索工作
$match = array('yes','test');
$array = array('m.title' => $match, 'm.msg' => $match);
$this->db->select('m.*');
$this->db->from('messages m');
$this->db->like($array);
$this->db->order_by('m.date', 'DESC');
$query = $this->db->get();
是否有任何用于此的 php codeigniter 代码?
谢谢!
【问题讨论】:
标签: php mysql arrays codeigniter search