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

    Join Date
    Jul 2013
    Posts
    2
    Rep Power
    0

    Code for calculating Price differences between selected item and other items


    Hey guys, how are you all doing

    Ive finished up my website and unfortunately I have a super inconvenient problem,

    the website sells gaming computers and I need a code to program it to calculate the price difference between the selected item and the rest of the items. in the category,

    As of now, I have manually duplicated each item to fit each different computer with the price difference to the default and the prices do not adjust once you select a different one.

    So I was wondering Is there a code that can be used so that I only have to upload one product and the website will automatically calculate the price difference between the items in each category?

    Like this :
    like Cyberpowerpc
    OR
    Xidax
    OR
    Alienware
    Thank you!

    the site was create in magento btw
    Last edited by ManiacDan; July 11th, 2013 at 02:33 PM.
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,294
    Rep Power
    9400
    Not sure what this "upload one product" means, but

    In your SQL query do a JOIN with the whatever table back against the whatever table: on one side is the original thing, on the other side is every other thing.
    Code:
    things
    
    id | name         | price
    ---+--------------+------
     1 | Cyberpowerpc |   100
     2 | Xidax        |   200
     3 | Alienware    |   300
    
    
    SELECT l.name, l.price, r.name, r.price, l.price - r.price AS diff
    FROM things l
    JOIN things r ON r.id != 2
    WHERE l.id = 2
    
    
    name  | price | name         | price | diff
    ------+-------+--------------+-------+-----
    Xidax |   200 | Cyberpowerpc |   100 |  100
    Xidax |   200 | Alienware    |   300 | -100
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    2
    Rep Power
    0
    Hi i Appologize i should have been a bit more clear

    Alienware xidax and cyberpowerpc are websites
  6. #4
  7. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,294
    Rep Power
    9400
    The actual labels in the example don't really matter. Pretend they're names for these items.

IMN logo majestic logo threadwatch logo seochat tools logo