Although I know PHP fairly well, I know nothing about ColdFusion and very little about arrays in either one. Can someone help me in porting over some code from ColdFusion to PHP?
What I have in ColdFusion is:
Obviously this is a shopping cart and is only a portion of the code although the rest is similarly simple.
What I have so far for creating the new array is:
but I am uncertain how to add or delete items, or edit quantities when the same item is selected again or changed.
As mentioned, I don't know arrays well but it appears that this is creating only a single array, then replacing it when a new item is added to the cart. I've searched this site and the Internet but much that I've found seems overkill for what I am trying to do and/or is over my head.
Note that aGetParam() is a custom function for getting form values.
Don
Experienced in HTML, Perl, PHP, VBScript, PWS, IIS and Apache and MS-Access, MS-SQL, MySQL databases
What I have in ColdFusion is:
Code:
<cfoutput query="get_price"><cfset Tprice = price></cfoutput>
<!--- cart logic --->
<CFIF NOT IsDefined("SESSION.aCart") OR ArrayIsEmpty(SESSION.aCart)>
<CFSET SESSION.aCart = ArrayNew(1)>
</CFIF>
<CFSET i = ArrayLen(SESSION.aCart) + 1>
<CFSET SESSION.aCart[i] = STRUCTNEW()>
<CFSET SESSION.aCart[i].ItemID = FORM.ItemID>
<CFSET SESSION.aCart[i].Price = FORM.Price>
<CFSET SESSION.aCart[i].Quantity = FORM.Quantity>
<CFSET SESSION.aCart[i].SUB_TOTAL = FORM.Price * FORM.QUANTITY>
Obviously this is a shopping cart and is only a portion of the code although the rest is similarly simple.
What I have so far for creating the new array is:
Code:
session_start();
$_SESSION["aCart", array("ItemID" => array($ItemID, "Price" => $Price, "Quantity" => aGetParam("Quantity"), "SubTotal" => number_format($Price * aGetParam("Quantity"), "2", ".", "")))];
but I am uncertain how to add or delete items, or edit quantities when the same item is selected again or changed.
As mentioned, I don't know arrays well but it appears that this is creating only a single array, then replacing it when a new item is added to the cart. I've searched this site and the Internet but much that I've found seems overkill for what I am trying to do and/or is over my head.
Note that aGetParam() is a custom function for getting form values.
Don
Experienced in HTML, Perl, PHP, VBScript, PWS, IIS and Apache and MS-Access, MS-SQL, MySQL databases