Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用autosuggest的独特查询_Php_Mysql_Distinct_Autosuggest - Fatal编程技术网

Php 使用autosuggest的独特查询

Php 使用autosuggest的独特查询,php,mysql,distinct,autosuggest,Php,Mysql,Distinct,Autosuggest,我正在尝试为我的autosuggest函数区分一列。这是我现在的疑问: $result=mysql_query("SELECT * FROM users WHERE firstname LIKE '%".mysql_real_escape_string($_GET['chars'])."%' ORDER BY firstname LIMIT 0, 10",$con) or die(mysql_error()); 不知何故,在select之后添加“DISTINCT firstname”是不起作用

我正在尝试为我的autosuggest函数区分一列。这是我现在的疑问:

$result=mysql_query("SELECT * FROM users WHERE firstname LIKE '%".mysql_real_escape_string($_GET['chars'])."%' ORDER BY firstname LIMIT 0, 10",$con) or die(mysql_error());
不知何故,在select之后添加“DISTINCT firstname”是不起作用的。(Javascript给出了一个错误。) 查询中的*是麻烦制造者,我猜,不知道确切原因

请协助编写正确的查询!:)

提前感谢

您可以使用“按名字分组”代替:

$result=mysql_query("
    SELECT * FROM users
    WHERE firstname LIKE '%".mysql_real_escape_string($_GET['chars'])."%'
    GROUP BY firstname ASC
    ORDER BY firstname
    LIMIT 0, 10",$con)
or die(mysql_error());

感谢1:快速回复,感谢2:正确解决方案,感谢3:本网站!非常感谢:)!不客气!如果答案是正确的,你应该在页面上标记为正确的,这样你的问题就不会保持“未回答”。