I'm trying to write some code that updates my db with a new qty value after 
someone makes a purchase on my Mal's shopping cart. You can tell Mal's to run a 
script via HTTP call after someone completes a purchase. It passes a cart 
variable to the script, and you can do what you like with it. I'm trying to 
loop through and update the qty field for all the items purchased. Could 
someone look at my logic and tell me how to improve it. I know this can't be 
right, but I've never written something like it before. It's commented well but 
let me know if you need more info.

<!---The cart info variable "#URL.cart#" arrives at my template via HTTP call, 
and looks like this.  description:quantity:price:productcode    delimited by ~

product description 1 blah blah:1:24.99:FX25~product description 2 blah 
blah:3:19.99:MX25~product description 3 blah blah:1:49.99:CX25

--->

<!---I want to replace all the semicolons with a comma to start off with--->

<cfset URL.cart = #Replace(URL.cart, ":", ". "ALL")#>

<!---So now our new variable should look like this: 

product description 1 blah blah,1,24.99,FX25~product description 2 blah 
blah,3,19.99,MX25~product description 3 blah blah,1,49.99,CX25

--->

<!--- I want to loop through this list of cart items, and update tblproducts 
"qtyonhand" field with the current number minus items passed from cart variable 
value. ~ is the delimeter for this list--->

<cfloop list="#URL.cart#" index="cartitem" delimeter="~">
   <cfset productcode = "#listgetat(cartitem, 4)#">
 <cfquery name="getqtys" datasource="#DSN#">
 SELECT qtyonhand FROM tblproducts 
 WHERE productcode='#productcode#'
 </cfquery>

   <cfset newqtyonhand = #getqtys.qtyonhand# - #listgetat(cartitem, 2)#>

<cfquery name="updateqtyonhand" datasource="#DSN">

UPDATE tblproducts SET(qtyonhand) VALUES(#newqtyonhand#)
WHERE productcode='#productcode#' 

</cfquery>
</cfloop>

Thanks,
Will

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Special thanks to the CF Community Suite Gold Sponsor - CFHosting.net
http://www.cfhosting.net

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:188351
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to