Can enyone help with this shopping cart?

Started on the old forum in May 2009 · view the original in the archive · old links redirect here

#help-needed #shopping-cart

No replies · 381 views · started 17 years ago · 1 min read

darryldw Newbie · 1 posts #1

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😕. Thank you your help is highly appreciated.

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>  <button type="submit" name="submit">Cornfirm and Proceed</button></div>';
          
        $output[] = '</form>';
    } else {
        $output[] = '<p>You shopping cart is empty.</p>';
    }
    return join('',$output);
}

?>

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close