July 11th, 2013, 12:40 PM
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 :
the site was create in magento btw
Last edited by ManiacDan; July 11th, 2013 at 02:33 PM.
July 11th, 2013, 01:37 PM
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.
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
July 11th, 2013, 02:07 PM
Hi i Appologize i should have been a bit more clear
Alienware xidax and cyberpowerpc are websites
July 11th, 2013, 02:17 PM
The actual labels in the example don't really matter. Pretend they're names for these items.