• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pass multi-dimensional array to hidden form

$product_ids = array(); //add this here before your first loop
foreach($product_list as $product){

In the loop, change
$product_id = array(
$product_ids[] = array(

remove this from your loop

and add this just outside of your loop, above where you calculate $sub_total.
$this->session->set_userdata('product_list', serialize($product_ids));

Im done with my problem. Thank you!! By the way how can i extract it to other page? So that i can view my product list? Using the foreach loop.

The way you did it can work too, however I would store $transact in session ONCE after your loops instead of many times in the loop. You're hitting the database kind of hard when you only need to hit it once for this.

In your place where you want to retrieve it, you just get the variable product_list from session like normal and unserialize it. Now its the original array containing an array for each product. The exact reverse of how you stored it.

I created a loop like this but i want to format like this:
Product ID: 1
Name: Test
Price: Test
Here is my code
$products = unserialize($this->session->userdata('product_list'));
    foreach($products as $element => $inner_array){
        echo "<strong>Product ID: ".$element."</strong><br>";
        foreach($inner_array as $items){
            echo $items."<br>";

How can i format like that?

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.