Hey,

Very good thanks for the code. Well you are actually setting a Query not a
structure. This will help you look for a value inside a query. By the way, I
am sorry for the script syntax. That's just the way I code. What we are
doing here is using valuelist to get a list of all the productID's. Then we
look at that list to see if the form.productID matches any of the list items
that we got from valuelist. Now using list get at we know the row number of
the query and we can change the value of other variables in that record
using that row number.

I know this is terrible huh. I think that this is the way everybody does
this type of thing. Did you get this from Ben Forta's first book? He uses a
shopping cart example that has functionality like this.

<cfscript>

 // check to see if the product is in the baset already
  productRow = listFind(valueList(session.basket.productID),
form.productID);

 // Product is in basket, update quantity
 if (productRow neq 0){

  // determine the new quantity and the correct row
  oldQuantity = listGetAt(valueList(session.basket.ProductQuantity),
productRow);
  newQuantity = form.ProductQuantity + oldQuantity;
       querySetCell(session.basket, "ProductQuantity", newQuantity);
       }

 // Product is not in basket, add it
 else  {
   queryAddRow(session.basket);

    //enter your syntax that adds the rest of the information you want...

   }

</cfscript>


Hope this helps.

Chris Cortes
Consultant
[EMAIL PROTECTED]
Direct 713-985-6244
Cell 832-723-6485

Stonebridge Technologies
...The Fast Track to e-Business.
visit us at www.sbti.com



----- Original Message -----
From: "Jon Tillman" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, September 09, 2000 3:25 PM
Subject: Re: Setting structure values


> Let me try again, and see if I dont confuse you this time:
>
> <!--- make the  structure --->
>         <cfset newBasket = queryNew("productID, quantity")>
>         <cfset session.basket = newBasket>
> <!--- add data to it --->
>         <cfset tempvalue = queryAddRow(session.basket)>
>         <cfset tempvalue = querySetCell(session.basket,
"#form.productID#", "#form.quantity_text#", AllowOverWrite)>
>
> Now, I need to take another FORM.productID, see if a record with the same
ID
> exists, and if so, add FORM.quantity to the second column in the
structure,
> given that ProductID is the first
>
> In your example below, it would be searching for the record "Chris" and if
it
> existed, adding something to the record "Cortes".
>
> Thank you for all of your help
>
> On Sat, 09 Sep 2000, Chris Cortes spake thusly:
> > Jon,
> >
> > I am sorry, I made some incorrect assumptions about what you were trying
to
> > do. I think what you want to do is check to see if an Item exists in the
> > Structure and then update its' value if it does. If this is correct the
> > following code should help you out.
> >
> >
> > <cfscript>
> >  // Create your structure...
> >  MyStruct = StructNew();
> >
> >  MyStruct.FName = "Chris";
> >  MyStruct.LName = "Cortes";
> > </cfscript>
> >
> > <!--- Lets output the structure to see how it looks... --->
> > Before the update:<br>
> > <cfloop list="#structKeyList(MyStruct)#" index="i">
> >
> >
<cfoutput>MyStruct.#i#</cfoutput>&nbsp;=&nbsp;<cfoutput>#evaluate("MyStruct.
> > #i#")#</cfoutput><br>
> > </cfloop>
> > <br>
> >
> > <cfscript>
> >  // Lets find the key and make the update if it exists...
> >  Form.Field = "Fname";
> >
> >  if(StructKeyExists(MyStruct,Form.Field)){
> >
> >   "MyStruct.#Form.Field#" = "Christopher";
> >
> >  }
> > </cfscript>
> >
> > <!--- Lets output the structure to see if the update was
successfull... --->
> > After the update:<br>
> > <cfloop list="#structKeyList(MyStruct)#" index="i">
> >
> >
<cfoutput>MyStruct.#i#</cfoutput>&nbsp;=&nbsp;<cfoutput>#evaluate("MyStruct.
> > #i#")#</cfoutput><br>
> > </cfloop>
> >
> >
> > PS I think that there is no function named StructFindNoCase(). There
really
> > is no need for it, because in ColdFusion, variable names are not
> > CaseSensitive...
> >
> > Chris Cortes
> > Consultant
> > [EMAIL PROTECTED]
> > Direct 713-985-6244
> > Cell 832-723-6485
> >
> > Stonebridge Technologies
> > ...The Fast Track to e-Business.
> > vvisit us at www.sbti.com
> >
> >
> >
> > ----- Original Message -----
> > From: "Jon Tillman" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Friday, September 08, 2000 10:31 PM
> > Subject: Re: Setting structure values
> >
> >
> > > On Fri, 08 Sep 2000, Chris Cortes spake thusly:
> > > > <cfif StructFindNoCase(session.basket, FORM.productID)>
> > > >
> > > >     <cfset myStructure.key = "#MyNewValue#">
> > > >
> > > > </cfif>
> > > >
> > > > All you need to do is set the structure key to the new value.
> > >
> > > So to update the found record to the form record would go something
like:
> > >
> > > <cfset #StructFindNoCase(session.basket, FORM.productID)# =
#MyFormValue#>
> > >
> > > ??
> > >
> > > --
> > > ***********************************************
> > >  Jon Tillman
> > >  LINUX USER: #141163
> > >  ICQ: 4015362
> > >  http://www.eruditum.org
> > >  [EMAIL PROTECTED]
> > > ***********************************************
> > > Help Jon build a network!
> > > Looking for giveaway computers & parts
> > > Current Need: Tape Drive & PI/PII processors
> > > Email me to find out how you can help
> > > ***********************************************
> > >
> >
> --------------------------------------------------------------------------
> > ----
> > > Archives: http://www.mail-archive.com/[email protected]/
> > > To Unsubscribe visit
> > http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk
or
> > send a message to [EMAIL PROTECTED] with 'unsubscribe'
in
> > the body.
> > >
> >
> >
>
> --------------------------------------------------------------------------
----
> > Archives: http://www.mail-archive.com/[email protected]/
> > To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or
send a message to [EMAIL PROTECTED] with 'unsubscribe' in
the body.
> --
> ***********************************************
>  Jon Tillman
>  LINUX USER: #141163
>  ICQ: 4015362
>  http://www.eruditum.org
>  [EMAIL PROTECTED]
> ***********************************************
> Be alert, the world needs more lerts
> ***********************************************
>
> --------------------------------------------------------------------------
----
> Archives: http://www.mail-archive.com/[email protected]/
> To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or
send a message to [EMAIL PROTECTED] with 'unsubscribe' in
the body.
>

------------------------------------------------------------------------------
Archives: http://www.mail-archive.com/[email protected]/
To Unsubscribe visit 
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a 
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.

Reply via email to