0

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

索引.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> 

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

4

1 回答 1

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>
于 2013-06-28T20:24:01.960 回答