#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    29
    Rep 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?
  2. #2
  3. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,264
    Rep Power
    968
    <cfif queryReturn["queryVariable"][x] neq false>
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    29
    Rep 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".
  6. #4
  7. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,264
    Rep Power
    968
    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>
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    29
    Rep 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.
  10. #6
  11. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,264
    Rep Power
    968
    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>
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    29
    Rep 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.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Posts
    131
    Rep Power
    7
    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.

IMN logo majestic logo threadwatch logo seochat tools logo