The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> ColdFusion Development
|
Complex object types cannot be converted to simple values?
Discuss Complex object types cannot be converted to simple values? in the ColdFusion Development forum on Dev Shed. Complex object types cannot be converted to simple values? ColdFusion Development forum discussing CFML coding practices, tips on CFML, and other CFML related topics. Find out why ColdFusion is the tool of choice for many e-commerce developers.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

March 5th, 2012, 04:33 PM
|
|
Registered User
|
|
Join Date: Feb 2012
Posts: 29
Time spent in forums: 10 h 56 m
Reputation Power: 0
|
|
|
Complex object types cannot be converted to simple values?
I want to loop through the results of a query:
Code:
<cfloop index="x" from="1" to="23">
<cfif queryReturn["queryVariable#x#"] neq false>
<!--- do stuff here --->
</cfif>
</cfloop>
This will toss a "complex object types cannot be converted to simple values" exception since it does not like the queryReturn["queryVariable#x#"] part. Anyway around this?
|

March 5th, 2012, 05:10 PM
|
|
Moderator
|
|
Join Date: Jun 2002
Location: Raleigh, NC
|
|
|
<cfif queryReturn["queryVariable"][x] neq false>
|

March 7th, 2012, 08:41 AM
|
|
Registered User
|
|
Join Date: Feb 2012
Posts: 29
Time spent in forums: 10 h 56 m
Reputation Power: 0
|
|
|
Thank you, that looks like it should do the trick but... it looks like it loops through everything that ends in whatever I name "queryVariable". Say I have "queryVariable1" through "queryVariable23", this will toss an error if I have another variables named "anotherQueryVariable". It'll say that "anotherQueryVariable" is not indexable by "queryVariable".
|

March 7th, 2012, 09:14 AM
|
|
Moderator
|
|
Join Date: Jun 2002
Location: Raleigh, NC
|
|
I don't really understand what you're saying. If you run this query and name it "myQuery":
select id, userName, isActive from users
If you then do this, it will work fine:
Code:
<cfloop index="x" from="1" to="#myQuery.recordCount#">
<cfif myQuery["isActive"][x] eq false>
<!--- this user is not active --->
</cfif>
</cfloop>
|

March 9th, 2012, 10:48 AM
|
|
Registered User
|
|
Join Date: Feb 2012
Posts: 29
Time spent in forums: 10 h 56 m
Reputation Power: 0
|
|
|
Whenever it hits the last column name, it just says it is not indexable by whatever I put in myQuery["isActive"][x]. I'm selecting everything out of the query, since I kind of have to with what I'm doing. There is probably about 40 columns, and 23 of those are checkboxes that have a boolean value. I'm just wanting to loop through just those instead of hardcoding them.
|

March 9th, 2012, 11:02 AM
|
|
Moderator
|
|
Join Date: Jun 2002
Location: Raleigh, NC
|
|
OK what you didn't make clear before is that you're not looping over the result set, you're looping over COLUMNS for each ROW of the result set.
Try something like this:
Code:
<cfloop index="thisRow" from="1" to="#myQuery.recordCount#">
<cfloop index="thisColumn" from="1" to="23">
<cfoutput>Value of queryReturn["queryVariable#thisColumn#"][#thisRow#] is : #queryReturn["queryVariable#thisColumn#"][thisRow]#<br/>
</cfloop>
</cfloop>
|

March 9th, 2012, 11:25 AM
|
|
Registered User
|
|
Join Date: Feb 2012
Posts: 29
Time spent in forums: 10 h 56 m
Reputation Power: 0
|
|
Worked like a charm! Thanks very much!
Edit: I never did anything like this. So I'm guessing we had to place the row as the index so that it would know where to go.
Code:
queryResults["queryVariable#thisColumn#"][#thisRow#]
Columns 1 through 23 of row whatever.
|

March 9th, 2012, 12:12 PM
|
|
Contributing User
|
|
Join Date: May 2008
Posts: 117
Time spent in forums: 17 h 16 m 2 sec
Reputation Power: 6
|
|
Quote: | Originally Posted by ColdBreeze So I'm guessing we had to place the row as the index so that it would know where to go. |
Yes. queryResults["queryVariable#thisColumn#"] points to a column object, not a simple string. It is similar to a one dimensional array, with each element representing a row value. So the index (ie row number) tells CF which value to retrieve.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|