Dysan Posted November 23, 2007 Share Posted November 23, 2007 How do I display the products, upon clicking the link contained in the writeShoppingCart() function? Also, upon executing the 'add' case within the switch statement, how do I also display the products? The products should also get displayed if the user manually enters the .php file, via entering the file path into their browsers address bar. How do I do this? <?php function writeShoppingCart() { echo "Shopping Cart: ".'<a href="test.php">'. "1 Items".'</a>'; } writeShoppingCart(); $id = $_GET['id']; $action = $_GET['action']; switch ($action) { case 'add': break; } echo "PRODUCTS:"; echo "Sky TV £500.00"; echo "Samsung Monitor £239.99"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/78545-display-products/ Share on other sites More sharing options...
binarymonkey Posted November 23, 2007 Share Posted November 23, 2007 I think this was answered in your other thread, but anyway: <?php function writeShoppingCart() { echo "Shopping Cart: ".'<a href="test.php?action=display">'. "1 Items".'</a>'; } function showProducts() { echo "PRODUCTS:"; echo "Sky TV £500.00"; echo "Samsung Monitor £239.99"; } writeShoppingCart(); $id = $_GET['id']; $action = $_GET['action']; switch ($action) { case 'add': showProducts(); break; case 'display': showProducts(); break; default: showProducts(); break; } ?> Why do you want to do essentially call the same function whatever way the page is called? You neednt bother with a switch structure in that case... Quote Link to comment https://forums.phpfreaks.com/topic/78545-display-products/#findComment-397467 Share on other sites More sharing options...
Dysan Posted November 23, 2007 Author Share Posted November 23, 2007 How do I do it how they've done it here: http://www.thewatchmakerproject.com/journal/276/building-a-simple-php-shopping-cart You simply click on the link, at it take you to the cart.php page, and displays whats in the shopping cart. # function writeShoppingCart() { $cart = $_SESSION['cart']; if (!$cart) { return '<p>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>You have <a href="cart.php">'.count($items).' item'.$s.' in your shopping cart</a></p>'; } } Quote Link to comment https://forums.phpfreaks.com/topic/78545-display-products/#findComment-397471 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.