• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

looping over a structure

Participant ,
Dec 04, 2006 Dec 04, 2006

Copy link to clipboard

Copied

How do I loop over this structure to populate it with a Query Recordset?

<cfset myStruct = objImage.getSize("images/products/largeImages/#Recordset1.elink#")>

I really appreciate your help.
TOPICS
Advanced techniques

Views

305

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 04, 2006 Dec 04, 2006

Copy link to clipboard

Copied

wouldn't you want to loop over the query data?

i'm guessing you have a struct (myStruct) that holds the image height/width (myStruct.height and myStruct.width)? what is it that's coming from the query that you want the struct to hold (that it's not currently holding)?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 05, 2006 Dec 05, 2006

Copy link to clipboard

Copied

I would like to populate the structure with the image file names that are coming from the query. The structure is built from a java object. Here is the function to create it.

<cfcomponent>
<cffunction name="getSize" returntype="struct" access="public" output="No">
<cfargument name="Image" required="Yes" type="string">
<cfset myImage = createObject("java", "javax.swing.ImageIcon")>
<cfset myImage.init(expandpath(arguments.Image))>
<cfset myStruct = StructNew()>
<cfset myStruct.width = myImage.getIconWidth()>
<cfset myStruct.height = myImage.getIconHeight()>
<cfreturn myStruct>
</cffunction>
</cfcomponent>

<cfobject component="imageSize" name="objImage">
<cfset myStruct = objImage.getSize("/images/someimage.jpg")>
<cfoutput>
width: #myStruct.width#
height: #myStruct.height#
</cfoutput>

Right now the structure only gives me the first row of the query. I have tried using the cfquery loop to populate the structure with now results. I suspect I am using the wrong syntac.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 05, 2006 Dec 05, 2006

Copy link to clipboard

Copied

well, a structure by design can only have one key with a given name. you can't have myStruct.height multiple times for multiple images returned from the query.

Sounds like you want an array of structs.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 06, 2006 Dec 06, 2006

Copy link to clipboard

Copied

LATEST
I tried running your code but I get this error.

<cfoutput query="Recordset1">
<cfset ArrayAppend(myArray, objImage.getSize("images/products/largeImages/#Recordset1.elink#")>
</cfoutput>

When I dump this it works.
<cfset myStruct = objImage.getSize("images/products/largeImages/#Recordset1.elink#")>
<cfoutput>#myStruct#</cfoutput>

The error I am getting says.
The CFML compiler was processing:

an expression beginning with "ArrayAppend", on line 23, column 13.This message is usually caused by a problem in the expressions structure.
a cfset tag beginning on line 23, column 7.


The error occurred in C:\CFusionMX7\wwwroot\flash\setSize.cfm: line 23

21 :
22 : <cfoutput query="Recordset1">
23 : <cfset ArrayAppend(myArray, objImage.getSize("images/products/largeImages/#Recordset1.elink#")>
24 : </cfoutput>
25 :


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation