【发布时间】:2011-09-08 14:25:34
【问题描述】:
我正在开发一个使用 PHP 和 Codeigniter 构建的 API,并使用 MySQL 作为数据库。
我有一个名为 Users 的用户表,其中包含以下列:
- 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']);
【问题讨论】:
-
为什么不起作用?你期望什么,反而会发生什么。
标签: php sql codeigniter