#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Posts
    36
    Rep Power
    7

    Litle help with pricing in cart


    Hi,
    i have a e-shop and i have some quantitative offers for some products.
    Example bellow:


    i want when the customers adds for example the quantity
    1 to 4 to the cart, the price of 15 euros,
    for 5 to 7 the price of 12 euros,
    for 8 to 11 the price of 10 euros
    and 12+ the price of 9 euros.

    how is this possible? do you have any idea?

    this is my SQL query
    Code:
    INSERT INTO cart (sessionid,prodID,qty,price VALUES ( '$sesid','$prodID','$qty','$price')
    this quantities and prices are in another table named "quant_prices".

    any idea?
    thanks in advance.
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1045
    Hi,

    Originally Posted by Kyriakos
    this quantities and prices are in another table named "quant_prices".
    Then we need to see that table.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Posts
    36
    Rep Power
    7
    Originally Posted by Jacques1
    Then we need to see that table.
    the quant_prices table is the table in the image above. it has 3 colums (prodID, qty, price)
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1045
    So the "other table" is in fact this one?

    Simply fetch the row with the biggest quantity not exceeding the quantity selected by the customer:

    sql Code:
    SELECT
    	ID
    	, MAX(Quantity)
    FROM
    	quant_prices
    WHERE
    	ID = ...
    	AND Quantity <= ...
    ;

    Given the ID and Quantity, you can now uniquely identify the price (assuming your primary keys are set up correctly).

    It might be a good idea to rename that "ID" column into something sensible like "product_id". Otherwise, everybody will think this is an AUTO_INCREMENT column.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".

IMN logo majestic logo threadwatch logo seochat tools logo