-1

I was wondering what will be the best way to show the number of items and the total price for those item which are already in cart(shopping basket).
The header.php page is on all my pages. so whatever page the user goes to they should be able to still see what the number of item in page and total price.

For an example if I had about 7 items my cart and let's say those item cost about $600.78. How cab I count those item up and show the number and total price in the div below.

example

Let's say u go on Nike website and buy 3 pairs of Nike shoes. If u look on top of the page it tells u how many items u have in your basket and the total price for all those items.

My header.php

<div class="cart">
<div class="shbag">
<a href ="cart.php">
</div>
<ul>         
                    <li class="item"><a>
                    Item
                    <span id="items">0</span>
                    </a></li>
                <li class="cart_price"><a href=""
                title="Cart">
                Total &#163;
                <span id="cart_total">0.00</span></a></li>  


                <!--cart page -->
                <li><a href="cart.php">
                <span class="check_bdr" 
                title="Checkout">View bag</span></a></li>
  </ul>


</div>

Thanks in Advance

4

1 回答 1

1

Here is my approach:

header.php

<?php require_once('minicart.php'); ?>

<div class="cart">
<div class="shbag">
<a href ="cart.php">
</div>
<ul>         
    <li class="item">
        Item <span id="items"><?php echo cart_item_count() ?></span>
    </li>
    <li class="cart_price">
        <a href="" title="Cart">Total &#163;
            <span id="cart_total"><?php echo cart_total() ?></span>
        </a>
    </li>  
    <!--cart page -->
    <li>
        <a href="cart.php">
            <span class="check_bdr" title="Checkout">View bag</span>
        </a>
    </li>
</ul>
</div>

minicart.php

<?php

function cart_item_count()
{
    return count($_SESSION['cart_array'])
}

function cart_total()
{
    // calculate your cart total here

    return $cart_total;
}
于 2013-07-14T17:42:54.440 回答