Answered
CFQuery inside of a loop
Can anyone show me the most efficient way of wrapping loops
around a query? I have a multi-select form field being passed
through the URL scope. The table I need to query looks like this:
region_id region_name
1 Africa
2 Asia
etc.
The variable url.region is passing the region_name and I need to do a lookup of the region_id through a query. Since this is a multi-select, there can be many regions in the variable. The code below doesn't yet loop and so only returns 1 value even if the url.region contains 2 or more values. Can anyone describe the best way of getting this to work?
<cfif IsDefined('url.region')>
<cfset regnList2 = ListQualify(url.region,"'",",","all")>
<cfquery name="GetRegionID" datasource="#myDB#">
select region_id from region
where region_name IN (#PreserveSingleQuotes(regnList2)#)
</cfquery>
</cfif>
Many thanks in advance!
Dave
region_id region_name
1 Africa
2 Asia
etc.
The variable url.region is passing the region_name and I need to do a lookup of the region_id through a query. Since this is a multi-select, there can be many regions in the variable. The code below doesn't yet loop and so only returns 1 value even if the url.region contains 2 or more values. Can anyone describe the best way of getting this to work?
<cfif IsDefined('url.region')>
<cfset regnList2 = ListQualify(url.region,"'",",","all")>
<cfquery name="GetRegionID" datasource="#myDB#">
select region_id from region
where region_name IN (#PreserveSingleQuotes(regnList2)#)
</cfquery>
</cfif>
Many thanks in advance!
Dave