COUNT,LIKE和EQUAL MySQL语句

时间:2013-05-31 11:48:43

标签: php mysql select

如何将MySQL中的COUNT,LIKE和“EQUAL”与PHP结合使用?我有以下查询,是我的“思考”权利。或者我完全错了?

$query = 'SELECT COUNT(string) 
        AS 
        nums, string, post_number, city, other 
        FROM 
        tld 
        WHERE 
        (string LIKE "%'.$searchQuery.'%" 
        OR 
        post_number LIKE "%'.$searchQuery.'%" 
        OR 
        city LIKE "%'.$searchQuery.'%" 
        OR 
        other LIKE "%'.$searchQuery.'%" 
        AND 
        city = '.$filterId.'
        GROUP BY 
        string 
        ORDER BY 
        string ASC';

1 个答案:

答案 0 :(得分:1)

尝试:

$query = 'SELECT COUNT(string) AS nums, string, post_number, city, other 
        FROM 
        tld 
        WHERE 
        (string LIKE "%'.$searchQuery.'%" 
        OR 
        post_number LIKE "%'.$searchQuery.'%" 
        OR 
        other LIKE "%'.$searchQuery.'%")
        AND
        (city LIKE "%'.$searchQuery.'%"
        OR
        city = '.$filterId.')
        GROUP BY 
        string 
        ORDER BY 
        string ASC';