php - How to store multiple value inside array and show them -


I am working on a shopping cart and I use car_id , value And add to session items. I managed to store in session, but how do I get them according to the ID?

Here is the code that stores inside the session:

  $ _ session ['item'] [$ value] = array ('total' = & gt; $ Car_id, 'add_on' = & gt; $ add_on);   

Similarly I get them back. I can show the ID and the value by adding it, but not the addon .. Because there can be many additional additions to the items in an ID and how can I retrieve the stores in the same way?

  & lt; Table & gt; & Lt; Tr & gt; & Lt; Th & gt; Price & lt; / Th & gt; & Lt; Th & gt; Car id & lt; / Th & gt; & Lt; Th & gt; Extra & lt; / Th & gt; & Lt; / Tr & gt; & Lt ;? Php foreach ($ _ session ['item'] as $ total = & gt; $ id) {? & Gt; & Lt; TR & gt; & Lt; Td width = "100" & gt; & Lt ;? Php echo 'rm' $ Total; & Gt; & Lt; / Td> & Lt ;? Php foreach ($ id $ as id) {? & Gt; & Lt; Td width = "100" & gt; & Lt ;? Php ek $ id ;? & Gt; & Lt; / Td> & Lt; Td width = "100" & gt; & Lt ;? Php if (isset ($ add_on)) {echo $ add_on;}? & Gt; & Lt; / Td> & Lt; / TR & gt; & Lt ;? Php}}? & Gt; & Lt; / Table & gt;   

Edit part **

How to reach the array inside the array?

Answer me on the above question

$ _ session ['item'] [$ price] = array (try to use multiple values ​​of '' editions stored in iris '' By doing so, total '=> $ car_id, array (' add_on '= & gt; $ add_on,' dep '= & gt; $ dep));

Edit How do I get an array of variable values ​​by URL

  if (isset ($ _ POST ['addon'])) {ifet ($ _ POST ['add_item'])) $ foreach ($ item as $ _ POST ['add_item']) {$ item. ' & Lt; Br / & gt; '; Mysql_select_db ($ databases); $ Query_item = "SELECT * FROM tbl_addons WHERE addOns_id = '$ item'"; $ Result_item = mysql_query ($ query_item); While ($ row_item = mysql_fetch_array ($ result_item)) {$ dep = $ row_item ['deposit']; $ PPD = $ row_item ['PricePerDay']; Counter repatriation '& Lt; Br / & gt; '; APO $ PPD '& Lt; Br / & gt; '; }}    

try it

  & lt; Table & gt; & Lt; Tr & gt; & Lt; Th & gt; Price & lt; / Th & gt; & Lt; Th & gt; Car id & lt; / Th & gt; & Lt; Th & gt; Extra & lt; / Th & gt; & Lt; / Tr & gt; & Lt ;? Php foreach ($ _ session ['item'] as $ total = & gt; $ id) {? & Gt; & Lt; TR & gt; & Lt; Td width = "100" & gt; & Lt ;? Php echo 'rm' $ Total; & Gt; & Lt; / Td> & Lt; Td width = "100" & gt; & Lt ;? Php ek $ id ['total'] ;? & Gt; & Lt; / Td> & Lt; Td width = "100" & gt; & Lt ;? Php if (isset ($ id ['add_on'])) {echo $ id ['add_on'];}? & Gt; & Lt; / Td> & Lt; / TR & gt; & Lt ;? Php}? & Gt; & Lt; / Table & gt;   

You do not need a second loop to get the price

Hope the way you want to store the add_on values Are 125), 'add_on2' = & gt; Array ('deposit amount' => 15%, 'value' => 234), 'add_on3' = & gt; Array ('deposit amount' => 5% ',' price '=> 54)));

Use this to retrieve values ​​

  & lt; Td width = "100" & gt; Php if (isset ($ id ['add_on'])) {foreach ($ id ['add_on'] as $ key = & gt; $ value) {echo $ key '; deposit - '. $ Value ['deposit']. ' ; value: '. $ Value ['value']; Echo '& lt; Br> & # 39; & # 39; }}? & Gt; & Lt; / Td>    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -