Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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