Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help building dynamic array

Status
Not open for further replies.

PushCode

Programmer
Dec 17, 2003
573
US
I'm working with a merchant account processing page and I need to submit product details to the merchant. The code provided by the merchant doesn't work for dynamic results...meaning they're code assumes each product is hard coded on the page. Here's what they have provided, but I need to make it work with query results.
Code:
<!--- CREATE THE ARRAY --->
<CFSET items = ArrayNew(2)>
<!--- FIRST ITEM --->
<CFSET item_id = "BC456">
<CFSET item_description = "Ball Cap">
<CFSET item_quantity = "1">
<CFSET item_price = "12.99">

<!--- EXAMPLE OF ADDING A SECOND ITEM --->
<CFSET item_id2 = "A98765">
<CFSET item_description2 = "T-Shirt">
<CFSET item_quantity2 = "3">
<CFSET item_price2 = "13.99">
	
<!--- ADD ITEMS TO THE ARRAY --->

<!--- FIRST ITEM --->
<CFSET items[1][1] = "#product_id#"> <!--- ITEM ID --->
<CFSET items[1][2] = "#prod_name#"> <!--- ITEM DESCRIPTION --->
<CFSET items[1][3] = "#quantity#"> <!--- ITEM QUANTITY --->
<CFSET items[1][4] = "#price#"> <!--- ITEM PRICE --->
		
<!--- EXAMPLE OF SECOND ITEM --->
<CFSET items[2][1] = "#product_id2#"> <!--- ITEM ID --->
<CFSET items[2][2] = "#prod_name2#"> <!--- ITEM DESCRIPTION --->
<CFSET items[2][3] = "#quantity2#"> <!--- ITEM QUANTITY --->
<CFSET items[2][4] = "#price2#"> <!--- ITEM PRICE --->

Here's what I have for an equivalent dynamic version...can anyone tell me if this looks right or not? I don't really get any error messages from the merchant account so I wanted to check with the experts here to see if this looks right.
Code:
<cfquery name="get_cart_items" datasource="#app.ds#">
	SELECT a.product_id, a.prod_name, a.price, a.sale_price, a.special, a.img_full, b.prod_size, b.gender, b.LR, b.quantity
	FROM products a, cart_items b
	WHERE a.product_id = b.product_id
	AND b.cart_id = '#form.cart_id#'
</cfquery>

<!--- CREATE THE ARRAY --->
<cfset items = ArrayNew(2)>
<cfset loopcount = 0>
<cfoutput>
<cfloop query="get_cart_items">
	<cfset loopcount = loopcount + 1>
	<CFSET item_id[#loopcount#][1] = "#get_cart_items.product_id#">
	<CFSET item_description[#loopcount#][2] = "#get_cart_items.prod_name#">
	<CFSET item_quantity[#loopcount#][3] = "#get_cart_items.quantity#">
	<CFSET item_price[#loopcount#][4] = "#get_cart_items.price#">
</cfloop>
</cfoutput>

Is this correct, am I missing anything? Thanks in advance!
 
I think it should be more like this

Code:
<cfset items = ArrayNew(2)>
<cfloop query="get_cart_items">
    <cfset row = ArrayNew(1)>
    <cfset row[1] = product_id >
    <cfset row[2] = prod_name >
    <cfset row[3] = quantity >
    <cfset row[4] = price >
    <cfset ArrayAppend(items, row)>
</cfloop>

<!--- show items --->
<cfdump var="#items#">
 
Thanks for the reply cfStarlight, I'll try that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top