coldfusion - Getting complex object error when trying to output query values -


my goal output column data specified in "fieldlist".

getting following error:

complex object types cannot converted simple values. expression has requested variable or intermediate expression result simple value, however, result cannot converted simple value. simple values strings, numbers, boolean values, , date/time values. queries, arrays, , com objects examples of complex values. cause of error trying use complex value simple one. example, might trying use query variable in cfif tag. error occurred on line 20.

when trying following:

<cfquery datasource="retailers" name="myquery"> select * retailer  retailer_id = '#url.id#' </cfquery>  <cfset fieldlist = "company,phone,phone_secondary,fax,email,website"> <cfloop list="#fieldlist#" index="i">       #myquery[i]# </cfloop> 

shouldn't work without giving me error? feel i'm overlooking simple can't find answer anywhere.

ok, see ammended initial code, here's response:

you looping on list of columns, , trying evaluate each column though single element in struct.

a query, however, different: accessed series of structs, in turn, arrays--of each row of data return query.

if want output of rows of data, without knowing columns front (or passing them in dynamically implying in code above), try this:

<cfoutput query="myquery">   <cfloop list="#myquery.columnlist#" index="thiscolumn">     #myquery[thiscolumn][myquery.currentrow]#   </cfloop> </cfoutput> 

this provide output need. outer cfoutput query attribute loop on rows of data received. then, each row, loop on list of columns query produces, , each column, output data, specifying row via myquery.currentrow, iterates automatically via outer output.

i'd take moment advocate try stay away loops within loops, , output values explicitly:

<cfoutput query="myquery">   #company# #phone# </cfoutput> 

using syntax less expensive aforementioned loop within loop.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -