php - Array increment in session -


array

$item= "stackoverflow"; $price = "30.00"; $total += ($sum * $price);  $cs1_array = array(); $cs1_array[] = array(     'item'=>array('item'=>$item, 'price'=>$price, 'quantity' => $sum),     'total' => $total );  $_session['session_inputs'] = $cs1_array; 

foreach loop in other page

$cs1_array = $_session['session_inputs']; echo "<table>"; foreach ($cs1_array $item){ echo "<tr>"; foreach ($item $item2){   echo "<td>{$item2['item']}</td><td>{$item2['price']}</td><td>{$item2['quantity']}</td>"; }  echo "<td>{$item['total']}</td>"; echo "</tr>"; } echo "</table>"; 

above the codes used display items in array display out 1 row of output,

stackoverflow 30.00 2 60

what want whenever submit html form, add new row new value array , output if submit 3 times

stackoverflow 30.00 2 60

stackoverflow 30.00 2 60

stackoverflow 30.00 2 60

you're overwriting $_session['session_inputs'] each time. make array , append it:

$cs1_array = array(     'item'=>array('item'=>$item, 'price'=>$price, 'quantity' => $sum),     'total' => $total ); $_session['session_inputs'][] = $cs1_array; 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -