-2

I'm having an array which I have included only once in the header.php file.

header.php:

<?
session_start();
include_once("array.php");
?>

array.php:

<?$foo["cart"] = array();?>

In the order.php I'm having an array and code which is executed when submitting a form. After the array_push you'll be redirected to the webshop.php, where you can view your shoppingcard.

order.php:

<? 
array_push($foo["cart"], array ('imagename'=>"$imagename",'size'=>"$size", 'price'=> "$price"));    $_SESSION["order"] = $foo;
?>

webshop.php:

<div class="shopping-card" > 
<? echo "<ol>";
for ($row = 0; $row < 3; $row++)
{
    echo "<li><b>Products:</b>";
    echo "<ul>";
    foreach( $_SESSION["order"]["cart"][$row] as $key => $value)
    {
        echo "<li>".$value."</li>";
    }
    echo "</ul>";
    echo "</li>";
}
echo "</ol>";
?>
</div>

enter image description here

As you can see here, it only shows the last value.

I hope you guys can help me out.

jarlh
  • 42,561
  • 8
  • 45
  • 63
Elvira
  • 1,410
  • 5
  • 23
  • 50
  • 1
    As far as I can see, it shows only the values of the FIRST row. But nothing here tells us that there are data in the second and third rows. Can you provide a `var_dump($_SESSION["order"]["cart"])` ? – xlecoustillier Jul 10 '15 at 07:26
  • 1
    I do not see how that code could output what you show at all. This code only outputs the inner, unordered list, not the outer, ordered list, and the literal phrase "Products:" does not appear at all. Could it be that this is _not_ the code you are actually using? – arkascha Jul 10 '15 at 07:27
  • What is in: $_SESSION["order"]["cart"][1] ..? – MaggsWeb Jul 10 '15 at 07:31

1 Answers1

0

You Have Make Array Like This :

Array
(
    [data] => Array
        (
            [0] => Array
                (
                    [Main] => stdClass Object
                        (
                            [cart_main_id] => 1
                            [cart_main_device_id] => AAAAAAA
                            [cart_main_table_id] => 36
                            [cart_main_table_number] => 18
                            [tbl_type] => 2
                        )

                    [orders] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [cart_detail_id] => 1
                                    [cart_detail_main_id] => 1
                                    [cart_detail_device_id] => AAAAAAA
                                    [cart_detail_product_id] => 5
                                    [cart_detail_qty] => 1
                                    [cart_detail_price] => 13.75
                                    [product_name] => #?#en#?#Turnips pork ribs soup#?#en#?##?#zh#?#èåœæŽ'骨汤#?#zh#?#
                                )

                            [1] => stdClass Object
                                (
                                    [cart_detail_id] => 1
                                    [cart_detail_main_id] => 1
                                    [cart_detail_device_id] => AAAAAAA
                                    [cart_detail_product_id] => 5
                                    [cart_detail_qty] => 1
                                    [cart_detail_price] => 13.75
                                    [product_name] => #?#en#?#Tom Yum Pork Ribs#?#en#?##?#zh#?#å†¬è«æŽ'骨#?#zh#?#
                                )

                        )

                )


        )

)

Then U CAn Extract The Right Value's From Array

    $tble_cnt = 0;

if (count($finalarray))
    {
    $ttlrcrds = count($finalarray['data']);
    $b = 0;
    for ($i = 0; $i < $ttlrcrds; $i++)
        {
        echo "Table No : " . $finalarray['data'][$i]['Main']->cart_main_table_number;
        $total_brand_cnt = count($finalarray['data'][$i]['orders']);
        for ($j = 0; $j < $total_brand_cnt; $j++)
            {
            $numbers_new = $j + 1;
            echo extract_language_part($finalarray['data'][$i]['product'][$j]->product_name, $this->session->userdata('current_language_iso'));
            }

        $tble_cnt++;
        }
    }
Kashyap Patel
  • 1,139
  • 1
  • 13
  • 29