CREATE TABLE `conf_discount` (
`id` int(10) unsigned NOT NULL auto_increment,
`discount` varchar(100) NOT NULL,
`money` varchar(100) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=cp1251;
INSERT INTO `conf_discount` VALUES (1, '2', '500000');
INSERT INTO `conf_discount` VALUES (2, '5', '1000000');
INSERT INTO `conf_discount` VALUES (3, '7', '5000000');
INSERT INTO `conf_discount` VALUES (4, '10', '10000000');
And another table with ORDERS
CREATE TABLE `orders` (
.....................
`pay_sum` int(10) NOT NULL,
) ENGINE=MyISAM;
Now i need to do query, so if Sum(pay_sum) > or = one of discount money print discount.
Like
$paysum = 604180;
if($paysum >= $discount['money']){
print("".$discount['discount']."%");
}else{
print("0%");
}
thanks and sorry for my little english.
Use your query to find this information for you.
What i assume you’re trying to do (and correct me if i’m wrong!) is store it so that if a person’s order is more than X dollars/pounds/spacebucks/whatever, they get Y% discount.
I assume you’re putting this information into a database because you want to be able to modify it through the GUI elsewhere, which is fine.
So lets use the database a little better.
Add a new record to your discount table which has discount 0, money 0.
Now,
SELECT discount
FROM conf_discount
WHERE money <= $paysum
ORDER BY money DESC
LIMIT 1;
(You may want/need to get more fancy with this if you’re trying to pull multiple records; additionally, if this display already has a record in the ‘order’ table, you may want to combine the two queries)
This will return a record with only the information you care about; the discount percent.