I am utilizing Bootstrap tabs to display some data in my ColdFusion project. I am attempting to loop through a list of classes that are returned from the database and then getting information based on that class. Here is the snippet of code that applies to my question:
<div class="tab-content" id="class-tabs-content">
<cfset allClassIDs = ValueList(classes.class_id)>
<cfset numOfClasses = ListLen(allClassIDs)>
<cfloop from="1" to="#ListLen(allClassIDs)#" index="i">
<cfset myIndex = ListGetAt(allClassIDs, i)>
<cfoutput>
<div class="tab-pane fade<cfif i EQ 1> show active</cfif>" id="panel-#myIndex#" role="tabpanel" aria-labelledby="tab-#myIndex#">
<!--- The following returns a cfquery --->
<cfset items = CreateObject("component", "com.modules.reels").getInventoryByDivisionAndClass("query", division.location_id, myIndex)>
#items.RecordCount# <-- CODE FAILS ON THIS LINE WITH MESSAGE "variable [ITEMS] doesn't exist"
</div>
</cfoutput>
</cfloop>
</div>
UPDATE: I tried a simpler example of what I was trying to do, and I got the same error: variable [ITEMS] doesn't exist. Here is the simplified code block I tried:
<cfset classes = CreateObject("component", "com.modules.reels").getClasses("query")>
<cfset ClassIDs = ValueList(classes.class_id)>
<cfloop from="1" to="#ListLen(ClassIDs)#" index="i">
<cfset ClassID = ListGetAt(ClassIDs, i)>
<cfoutput>
<cfset items = CreateObject("component", "com.modules.reels").getInventoryByDivisionAndClass("query", 3, ClassID)>
<cfdump var = "#items#">
</cfoutput>
</cfloop>
I do not understand what could possibly be going on here! How can the variable not exist when I set it on the previous line and the cfset did not throw an error? Please help!
Thank you to @rrk for your comments. As it turns out (and I feel really stupid), getInventoryByDivisionAndClass()
was missing its <cfreturn>
statement!