Reputation: 2577
I often have to switch between a code and name from a query in my code. Here's what it looks like:
<cfquery name="AllLocations" >
Select Name, Code From Locations
</cfquery>
Later in the page I will need the name and have the code, or visa-versa:
<cfquery name="ThisLocation" dbtype="query >
Select Name From Locations where Code = '#Code#'
</cfquery>
<cfoutput>#ThisLocation.Name#</cfoutput>
Is there a shorter way to do this so I don't have to do the qoq every time?
Upvotes: 0
Views: 69
Reputation: 20804
You could do something like this:
<cfoutput>
#allLocations.name[listfind(valuelist(allLocations.code), code)]#
</cfoutput>
Edit starts here Given the comment about performance, I understand that arrays are faster than lists.
<cfoutput>
#allLocations.name[arrayFind(allLocations['code'], code)]#
</cfoutput>
Upvotes: 1