Can enyone help with this shopping cart?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Can enyone help with this shopping cart?

    Can somebody please help me to write multiple items that has been added to my shopping cart into a table called "orderd_products_td" with the amount due and quantity for each product = to the user_id for each user:confused:. Thank you your help is highly appreciated.

    PHP Code:
    function writeShoppingCart() {
        $cart = $_SESSION['cart'];
        if (!$cart) {
            return '<p class="Title">You have no items in your shopping cart</p>';
        } else {
            // Parse the cart session variable
            $items = explode(',',$cart);
            $s = (count($items) > 1) ? 's':'';
            return '<p class="content">You have <a href="cart.php" class="content">'.count($items).' item'.$s.' in your shopping cart</a></p>';
        }
    }
    
    function showCart() {
        global $db;
        $cart = $_SESSION['cart'];
        if ($cart) {
            $items = explode(',',$cart);
            $contents = array();
            foreach ($items as $item) {
                $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
            }
            $output[] = '<form action="cart.php?action=update" method="post" id="cart">';
            $output[] = '<table>';
            foreach ($contents as $id=>$qty) {
                $sql = 'SELECT * FROM products_td WHERE id = '.$id;
                $result = $db->query($sql);
                $row = $result->fetch();
                extract($row);
                $output[] = '<tr>';
                $output[] = '<td><a href="cart.php?action=delete&id='.$id.'" class="r"><img src="../images/remove.png" border="0" /></a></td>';
                $output[] = '<td width="250" class="content"><strong>Product:</strong> '.$product_name.' <br /><strong>Description:</strong> '.$product_descript.'</td>';
                $output[] = '<td class="content">R '.$product_price.'</td>';
                $output[] = '<td class="content"><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>';
                $output[] = '<td class="content">R '.($product_price * $qty).'</td>';
                $total += $product_price * $qty;
                $output[] = '</tr>';
            }
            $output[] = '</table>';
            $output[] = '<p class="smallcontent">Grand total: <strong>R '.$total.'</strong></p>';
            $output[] = '<div><button type="submit">Update cart</button> &nbsp;<button type="submit" name="submit">Cornfirm and Proceed</button></div>';
              
            $output[] = '</form>';
        } else {
            $output[] = '<p>You shopping cart is empty.</p>';
        }
        return join('',$output);
    }
    
    ?> 
    
    Last edited by metulj; 19.05.09, 14:57. Reason: use [ php ] ... [ / php ] tag for posting code
Working...
X