我正在開發一個使用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