Jump to content

Display Products


Dysan

Recommended Posts

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";

?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/78545-display-products/
Share on other sites

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...

Link to comment
https://forums.phpfreaks.com/topic/78545-display-products/#findComment-397467
Share on other sites

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>';
  }
}

Link to comment
https://forums.phpfreaks.com/topic/78545-display-products/#findComment-397471
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.