我正在开发一个使用PHP和Codeigniter构建的API,我使用MySQL作为数据库。用全名搜索而不是名字或姓氏
我有一个用户表称为用户,包含以下几列:
- ID
- Firstname
- Lastname
- Email
如何使用全名的用户搜索这个表?例如,它可以很好地搜索Martin或Smith,但不是Martin Smith。
这是我现在使用的查询:
$this->db->select('*');
$this->db->from('users');
$this->db->like('firstname', $args['query']);
$this->db->or_like('lastname', $args['query']);
更新
如果我使用此查询的建议下面我无法找到任何东西。不包含全名,名字或姓氏。然后,名字和姓氏必须是相同的单词。
$this->db->select('*');
$this->db->from('users');
$this->db->like('firstname', $args['query']);
$this->db->like('lastname', $args['query']);
为什么犯规工作?你期望什么,取而代之的是什么。 – TJHeuvel