Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Banned
    Join Date
    Oct 2007
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Add to Shopping Cart

    OK, For testing/development purposes, I have the following code to display all the products contained inside the database.
    How do I display each record/product along with a button to add the product to the shopping cart/session?

    Code:
    mysql_select_db("Data", $con);
    
    $result = mysql_query("SELECT * FROM Products");
    
    while($row = mysql_fetch_array($result))
    {
      echo $row['Name'];
      echo $row['Price'];
    }
    
    mysql_close($con);
    ?>

  • #2
    Regular Coder
    Join Date
    Jul 2005
    Location
    Oxfordshire, UK
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts
    just add your button in after echo $row['Price']; but before the closing }

    you could use a graphic button, a form or text. for example.


    Code:
    mysql_select_db("Data", $con);
    
    $result = mysql_query("SELECT * FROM Products");
    
    while($row = mysql_fetch_array($result))
    {
      echo $row['Name'];
      echo $row['Price'];
      echo '<a href="add_to_cart.php">Add to Cart</a>';
    }
    
    mysql_close($con);
    ?>
    you would need to add in the id of the product so the add_to_cart page knows which product you have selected.

  • #3
    Banned
    Join Date
    Oct 2007
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK, Cheers What code goes inside the add_to_cart.php file?

  • #4
    Regular Coder
    Join Date
    Jul 2005
    Location
    Oxfordshire, UK
    Posts
    144
    Thanks
    0
    Thanked 0 Times in 0 Posts
    might i suggest you take a look at: http://www.thewatchmakerproject.com/...-shopping-cart


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •