Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-28-2007, 06:33 PM   PM User | #1
Cerby
Banned

 
Join Date: Oct 2007
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Cerby has a little shameless behaviour in the past
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);
?>
Cerby is offline   Reply With Quote
Old 10-28-2007, 06:49 PM   PM User | #2
robojob
Regular Coder

 
Join Date: Jul 2005
Location: Oxfordshire, UK
Posts: 144
Thanks: 0
Thanked 0 Times in 0 Posts
robojob is an unknown quantity at this point
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.
robojob is offline   Reply With Quote
Old 10-28-2007, 07:00 PM   PM User | #3
Cerby
Banned

 
Join Date: Oct 2007
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
Cerby has a little shameless behaviour in the past
OK, Cheers What code goes inside the add_to_cart.php file?
Cerby is offline   Reply With Quote
Old 10-28-2007, 07:04 PM   PM User | #4
robojob
Regular Coder

 
Join Date: Jul 2005
Location: Oxfordshire, UK
Posts: 144
Thanks: 0
Thanked 0 Times in 0 Posts
robojob is an unknown quantity at this point
might i suggest you take a look at: http://www.thewatchmakerproject.com/...-shopping-cart
robojob is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:30 AM.


Advertisement
Log in to turn off these ads.