php - 带模式的搜索字符串查询
问题描述
我有一张如下表
表格1
id type
1 Aches, Pain, Fever
2 Fever
3 Fever Blisters
4 Hay Fever
5 Typhoid Fever
6 Valley Fever
7 Viral Hemorrhagic Fever
8 Yellow Fever
9 Fever with chills
10 Fever well
11 Day fever
12 Fever from week
13 Dengue Fever
14 Fever with cold
15 Fever with chills One
16 Fever hi
17 high grade fever
表2
id type
1 Acute Valley Fever
2 Allergic Rhinitis (Hay Fever)
3 Breakbone Fever
4 Coccidioidomycosis (Valley Fever)
5 Typhoid2 Fever
6 Valleyrt Fever
我正在尝试使用 php codeigniter
$this->db->select("id,type");
$this->db->from('table1');
$this->db->like('type', $searchterm, 'after');
$query1 = $this->db->get_compiled_select();
$this->db->select("id,type");
$this->db->from('table1');
$this->db->like('type', $searchterm, 'both');
$this->db->not_like('type', $searchterm, 'after');
$query2 = $this->db->get_compiled_select();
$searchResult = $this->db->query($query1 . " UNION " . $query2)->result();
if (sizeof($searchResult) > 0) {
return $searchResult;
} else {
return [];
}
我想使用关键字“发烧”在搜索中显示类型列表。我想要 table1 和 table2 的输出如下
- 首先显示以关键字“发烧”开头的类型
- 然后显示包含关键字 'fever' 作为子字符串的类型
我该怎么做才能从另一个表中获取记录?
解决方案
推荐阅读
- html - 将收音机与自定义收音机对齐
- ios - 如何保持 UNUserNotificationCenter 声音播放直到用户停止它
- java - 取消计划的计时器任务并创建另一个计划
- java - 没有为 AuthenticationSuccessEvent 调用 Spring 安全 ApplicationListener
- javascript - 为什么调用 Function.apply.bind(fn, null) 调用 `fn.apply`,而不是 `Function.apply`?
- audio - 使用 sox 转换音频文件,同时保留日期/时间信息
- python - Python不会从命令行中提取多个参数
- xml - Blogger 中的面包屑
- python - Python GUI 示例的在线界面
- asp.net - 将来自网络抓取的响应保存为 csv 文件