如何自动完成忽略倍数?

时间:2013-06-28 19:28:26

标签: coldfusion autocomplete

你好我有这样的自动完成设置:

index.cfm

<!--- A simple form for auto suggest --->
<cfform action="autosuggest.cfm" method="post">
    Park Name:<br />
    <cfinput type="text" name="parkname" size="50" autosuggest="cfc:autosuggest.findPark({cfautosuggestvalue})" autosuggestminlength="1" maxresultsdisplayed="10" /><br /><br />
</cfform>

和autosuggest.cfc

<cfcomponent output="false">

    <!--- Lookup used for auto suggest --->
    <cffunction name="findPark" access="remote" returntype="string">
        <cfargument name="search" type="any" required="false" default="">

        <!--- Define variables --->
        <cfset var local = {} />

        <!--- Query Location Table --->
        <cfquery name="local.query" datasource="#application.datasource#" >
            select      FirstName
            from        Users
            where       FirstName like <cfqueryparam cfsqltype="cf_sql_varchar" value="#ucase(arguments.search)#%" />
            order by    FirstName
        </cfquery>

        <!--- And return it as a List --->
        <cfreturn valueList(local.query.FirstName)>
    </cffunction>

</cfcomponent> 

我需要它做的是忽略倍数。而不是这样:戴夫,杰克,杰克,杰克,切特。它应该只这样做:戴夫,杰克,切特。我该怎么做呢?

1 个答案:

答案 0 :(得分:0)

您需要在查询中使用SELECT DISTINCT

<cfquery name="local.query" datasource="#application.datasource#" >
select      DISTINCT FirstName
from        Users
where       FirstName like <cfqueryparam cfsqltype="cf_sql_varchar" value="#ucase(arguments.search)#%" />
order by    FirstName
</cfquery>