After
I became a shopping cart system, and my session is being displayed with a foreach () function. Inside this function, I have a variable named $ item_price I would like to add all $ item_price so that I can finish it altogether.
How can this be done? /
This is my foreach () code :: I have no clue to how this problem should be resolved
foreach ($ session_cart $ cart_items ) {$ Fetch_info = Mysql_query ("Select * from shop_items` where item_id = '$ cart_items'"); While ($ shop_items = mysql_fetch_array ($ fetch_info)) {$ ITEM_ID = $ shop_items ['ITEM_ID']; $ Item_name = $ shop_items ['item_name']; $ Item_quantity = count (array_keys ($ session_quantity, $ item_id)); $ Item_price = $ shop_items ['item_price'] * $ item_quantity; } $ CartOutput = '& Lt; H2 & gt; $ Item_name '& Lt; / H2 & gt; '; $ CartOutput = '& Lt; A & gt; Quantity: '$ item_quantity.' & Lt; / A & gt; & Lt; Br> '; $ CartOutput = '& Lt; A & gt; value: '. Number_format (float) $ item_price, 2, '.', ''). ' US dollar & lt; / A & gt; & Lt; Br> '; $ CartOutput = '& Lt; A & gt; Id: '. $ Item_id. ' & Lt; / A & gt; & Lt; Br> & Lt; Br> '; } itemprop = "text"> Use the updated code:
$ total = 0; Foreach ($ session_cart $ as cart_items) {$ fetch_info = mysql_query ("Choose from shop_items` * Where ITEM_ID = '$ cart_items'"); // while ($ shop_items = mysql_fetch_array ($ fetch_info)) {// & lt; - Only one return will be returned in the form of every $ shop_items = mysql_fetch_assoc ($ fetch_info) loop is not needed; // & lt; - Instead use $ item_id = $ shop_items ['item_id']; $ Item_name = $ shop_items ['item_name']; $ Item_quantity = count (array_keys ($ session_quantity, $ item_id)); $ Item_price = $ shop_items ['item_price'] * $ item_quantity; //} // & lt; - Loop $ cart removed while closing = '& Lt; H2 & gt; $ Item_name '& Lt; / H2 & gt; '; $ CartOutput = '& Lt; A & gt; Quantity: '$ item_quantity.' & Lt; / A & gt; & Lt; Br> '; $ CartOutput = '& Lt; A & gt; value: '. Number_format (float) $ item_price, 2, '.', ''). ' US dollar & lt; / A & gt; & Lt; Br> '; $ CartOutput = '& Lt; A & gt; Id: '. $ Item_id. ' & Lt; / A & gt; & Lt; Br> & Lt; Br> '; $ Total + = $ ITEM_PRICE; // and & lt; - Lists for Grand Total} $ echo per dollar; // & lt; - Shows grand total
Comments
Post a Comment