如何在此查询中包含要搜索的其他列?

时间:2014-04-19 08:46:34

标签: php mysql sql

我试图修改搜索脚本。下面是我认为当前搜索电子邮件的完全匹配以及名字和姓氏匹配的代码的一部分。我也希望它在名为' details'的列中搜索匹配(部分和完整)。我需要更改什么才能尝试所有三种搜索模式?

//begin snippet

if($qt == 1) {
                $query = $this->db->query(sprintf("SELECT * FROM `users` WHERE `email` = '%s' LIMIT 1", $this->db->real_escape_string($value)));
            } else {
                $query = $this->db->query(sprintf("SELECT * FROM `users` WHERE `username` LIKE '%s' OR concat_ws(' ', `first_name`, `last_name`) LIKE '%s' ORDER BY `verified` DESC, `idu` DESC LIMIT %s, %s", '%'.$this->db->real_escape_string($value).'%', '%'.$this->db->real_escape_string($value).'%', $this->db->real_escape_string($start), ($per_page + 1)));

                // Sometimes the query might fail due to the fact that utf8 characters are being passed and the `username` sql field does not allow special chars
                if(!$query) {
                    $query = $this->db->query(sprintf("SELECT * FROM `users` WHERE concat_ws(' ', `first_name`, `last_name`) LIKE '%s' ORDER BY `verified` DESC, `idu` DESC LIMIT %s, %s", '%'.$this->db->real_escape_string($value).'%', $this->db->real_escape_string($start), ($per_page + 1)));
                }

0 个答案:

没有答案