please disregard this post. I have made a clearer example of my problem here: Error with CFLoop When Entries Are Missing
I am running the CFLoop code below.
<cfset data = queryNew("sid,firstname,lastname,age","integer,varchar,varchar,integer")>
<cfloop index="x" from="1" to="50">
<cfset queryAddRow(data)>
<cfset querySetCell(data,"sid",x)>
<cfset querySetCell(data,"firstname","#first[x]#")>
<cfset querySetCell(data,"lastname","#last[x]#")>
<cfset querySetCell(data,"age","#studentage[x]#")>
</cfloop>
<cfoutput query="data">
#sid# - #firstnamet# #lastname# - #age#<br />
</cfoutput>
The variables first[x]
, last[x]
, and studentage[x]
are being pulled from an external datasource, with X
being the loop index. Note that the CFLoop has 50 entries.
When there is data available, the code works beautifully. However, when there is missing data, the code breaks. By that I mean if Entry 11 doesn't have a name listed for the first[x]
variable I get an error along the lines of "Element first is undefined. The error occurred on line 5
(line 5 is the entry for first name).
When this happens, I would like to omit entry 11 (and all other entries which cause an error) from my results and prevent the error from showing. How can I do this?
Clarification: Please assume the data is defined. It gets a bit hairy since I am using an external datasource. But what I am saying is that Entries 1 to 10 show up. When its entry 11's turn, that's when the error comes up.