Jump to content

PapaBurgundy

Members
  • Posts

    12
  • Joined

  • Last visited

    Never

Everything posted by PapaBurgundy

  1. $sql = "SELECT products.product_id, products.product_price, order_prod.order_quan, products.product_price * order_prod.order_quan AS product_subtotal, SUM(product_subtotal) AS total_order_price"."----------------------------------sum line which doesn't work FROM products, order_prod"." WHERE products.product_id = order_prod.product_id "." AND order_prod.order_id = " . $_GET["order_id"]." ORDER BY products.product_id"; $get = mysql_query($sql); if(mysql_num_rows($get)==0){ echo "Sorry but there is nothing available."; }else{ while ($get_data = mysql_fetch_assoc($get)){ echo $get_data['product_subtotal']; echo $get_data['total_order_price'];-----------------------------total order price echoed here I just want to add up the values of the subtotals of each product. So my product_subtotal would be multiplying the quantity of the product by the price of the product. I then want to add all of those quantity subtotals together to give an order total. So sample output, Product name Quantity Product price Subtotal product name1 1 £350.00 £350.00 product name2 4 £70.00 £280.00 Order total price £630.00 I just want to add together the subtotals to get a total order price. Sorry if my explanation isn't great; my brain has been used and abused this past few weeks.
  2. I sort of realized that through my trial and error haha but was hoping it would work anyway. Is there actually a way to total a set of returned values from a sum?
  3. $sql = "SELECT products.product_id, products.product_price, order_prod.order_quan, products.product_price * order_prod.order_quan AS product_subtotal"." FROM products, order_prod"." WHERE products.product_id = order_prod.product_id "." AND order_prod.order_id = " . $_GET["order_id"]." ORDER BY products.product_id"; $get = mysql_query($sql); if(mysql_num_rows($get)==0){ echo "Sorry but there is nothing available."; }else{ while ($get_data = mysql_fetch_assoc($get)){ echo $get_data['product_subtotal']; Some more code as requested, I hope this helps!
  4. Hi, I have a mysql_query within PHP that multiplies the price of a product by the quantity bought of that product to give a subtotal. products.product_price * order_prod.order_quan AS product_subtotal This works fine and is called upon using ($get_data['product_subtotal'] As you would expect. My only problem is that I need to get a total order cost. I thought that it would merely be a case of doing something like SUM(product_subtotal) AS total_order_price But this brings back nothing. I know this must be very simple as it's only adding together a few values, but I've been stuck on this same problem for hours and time is running out ahhh Any ideas?
  5. Thanks for the help. I did figure it out, and think I deserve a slap in the face for why i couldn't get it to work... The foreach loop worked. But for some reason it just wouldn't insert any of the data into the table until I created an auto incrementing column. That's about 3 days work to figure that out haha Thanks again!
  6. I am setting up a PHP & MySql shopping cart. When a user adds products they are stored as sessions. The cart displays the products in an array: foreach($_SESSION as $product => $quantity) So the product is the product_id, and the quantity is the quantity of that product which has been added. When getting the information from the database to display it, it reads like this 1-----2 (product_id = 1, quantity = 2) 2-----1 (product_id = 2, quantity = 1) 3-----3 (product_id = 3, quantity = 3) 11---12 (product_id = 11, quantity = 12) 4-----1 (product_id = 4, quantity = 1) I'm basically trying to insert the product_id and quantity into a table called cart. I've been stuck for days and can still only manage to insert 1 row of values Searching around I saw that some people inserted arrays using implode or explode functions first, but I'm not sure how that would work in this case Any ideas?
  7. I thought I had it sussed, but after a few more hours of attempting to get it working I am again stuck. I started using the session_id() which brought up nice long session id. From this I can see how it can be used, however is there a way to get this session_id() is auto increment or change after the person's details have been submitted? I've tried all sorts, I think the closest I got was $session_id = session_id(); $session_id++; Unfortunately this only incremented once, I tried placing it after the order details had gone through as well but still nothing. I also thought about a function which checks to see if the session_id(), is equal to or less than, session_id in the database. This way the next session_id() would always be different
  8. Hmmm maybe I'm thinking about this too hard then? EDIT** Half way through typing this I finally understand what you're all on about, and yeah I was thinking too hard haha. I used what fugix had posted and it works. So simple Thanks!
  9. The problem with using session id is that there is a session id for each product in the cart. So if I were to put this into the database it would store each product individually, which I want, but it wouldn't have an id code for the entire session. Also, I'm guessing that if I auto incremented an id for the order, it would auto increment with every product entered into the database on that session. So products from the same order would have different order ids. I'm gonna try the mysql_insert_id() and see what I can come up with. Otherwise I'm gonna try some dodgy approach of entering the current time and date for each order and then referencing those to a separate id. Thanks!
  10. Basically I'm trying to set up a shopping cart using PHP & MySql (oh really!?) and I've gotten to the point where I need to insert the bought products into a database. Currently, at the checkout, there is a session which stores data for all of the products which have been added into the cart. From here I am just trying to create an order id code that is only relevant to this session. So in the database it would end up looking something like this: order_id = 001, product_id = 2, order_quantity = 3 order_id = 001, product_id = 4, order_quantity = 2 order_id = 001, product_id = 1, order_quantity = 5 order_id = 002, product_id = 2, order_quantity = 3 order_id = 002, product_id = 4, order_quantity = 2 order_id = 002, product_id = 1, order_quantity = 5 So I would be able to pull these results later by selecting the order relevant to the order_id. At least I think this is the easiest option for me. Every product which is put into the cart has a $_SESSION name of 'product_x', 'x' being the id associated with that product Any help?
  11. if(isset($_GET['add'])){ $_SESSION['repair_'.(int)$_GET['add']]+='1'; //if the 'add' is set then create a session named with the id used header('Location: order.php'); } This is the code I'm using to add a product to the cart. I've tried some variations but it doesn't seem to do what I want it to as it's already set up to handle more data.
  12. Hi I'm currently in the process of making a small online shop. At the moment I only want the site to function by allowing the user to purchase one product. It all works fine apart from one feature. The user could have one product in their cart, but then click back onto the products page and order another product; this would put the price up but only store one product in the database. Is there a way to destroy the cart session with the user leaving the page? Or either some sort of function which stops the user from leaving the page until they clear their cart? My code to delete a product from the cart //delete item from cart if(isset($_GET['delete'])){ $_SESSION['cart_'.(int)$_GET['delete']]='0'; header('Location: order.php'); } My first idea was to take this code and somehow relate or apply it to every link, but I'm guessing there's an easier way around that. The error message would make more sense to me but I can't seem to find anything anywhere. Thanks!
×
×
  • 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.