I have a database table with three columns: ID, UserName, UserLoc. I need
to be able to search on the first four letters of a users last name, the
names are stored in this format: lastname, firstname. When I find a
matching criteria I need to highlight those records in a list I am
displaying, if I do not find any matches I need to know which two records
the criteria would fall in between if it did exist in the table. My current
method to do this is below, is there a better way to do this?
---------------------Code-------------------
<cfquery name="qryGetInfo" datasource="Testing">
SELECT ID, UserName, UserLoc
FROM tblUsers
ORDER BY UserName DESC
</cfquery>
<CFSET tmp = ListSort(ValueList(qryGetInfo.UserName, "|"), "Textnocase",
"desc", "|")>
<cfif IsDefined("Form.UserName")>
<cfset tmp = ListSort(ListAppend(tmp, Form.UserName, "|"), "Textnocase",
"desc", "|")>
<cfset Item1 = ListFind(tmp, Form.UserName, "|") - 1>
<cfset Item2 = ListFind(tmp, Form.UserName, "|")>
<cfset UserName = Form.UserName>
<cfelse>
<cfset UserName = "">
<cfset tmp2 = "">
</cfif>
<cfoutput>
<cfloop index="ABR" list="#tmp#" delimiters="|">
<div class="#IIf(Left(ABR,4) EQ UserName, DE('Selected'),
DE(''))#">#ABR# -- <cfif ABR NEQ
UserName>#qryGetInfo.UserLoc[(ListFind(ValueList(qryGetInfo.UserName, "|"),
ABR, "|"))]#</cfif></div>
</cfloop>
</cfoutput>
-----------------End Code------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists