You could do this is you wanted to store several things about each item
(name, decription, price...)

<cfset oldPrice = structNew()>
<cfloop query = "getInventory">
        <cfset oldPrice[item_id] = structNew()>
        <cfset oldPrice[#item_id#].price = price>
        <cfset oldPrice[#item_id#].description = description>
</cfloop>

But since you only want one thing you don't need a structure of structures.
A simple structure will do:

<cfset oldPrice = structNew()>
<cfloop query = "getInventory">
        <cfset oldPrice[item_id] = price>
</cfloop>

Now to get a price of item 123, you'd write:

<cfoutput>#Oldprice[123]#</cfoutput>



> -----Original Message-----
> From: Chris [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, 16 July 2003 5:49 p.m.
> To: CF-Talk
> Subject: Structure or Array or both?
> 
> I have a problem and I'm guessing that a simple structure is my answer but
> I
> have never done one before so here I am.  I need to access a price based
> upon an item number.  Do I query the table to get my item id and price
> then
> loop over the query and create a structure, or more accurately I guess a
> set
> of structures so when I need a price I can just use #itemid.price#?  If so
> how do I execute this?
> 
> 
> 
> My thought was something like this:
> 
> 
> 
> <cfloop query = "getInventory">
> 
>  <cfset oldPrice[#item_id#] = structNew()>
> 
>  <cfset oldPrice[#item_id#].price = #price#>
> 
> </cfloop>
> 
> 
> 
> This of course does not work.  I will have an item id at the location
> where
> I need to display the price so I was thinking that my output could be
> #Evaluate("oldPrice#item_id#.price")#
> 
> 
> 
> Am I even close?
> 
> 
> 
> Any assistance would be greatly appreciated.
> 
> 
> 
> Chris
> 
> 
> 
> 
> 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: 
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq

Signup for the Fusion Authority news alert and keep up with the latest news in 
ColdFusion and related topics. 
http://www.fusionauthority.com/signup.cfm

                                Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
                                

Reply via email to