Jump to content

Help With Query -- Ranges


coast917

Recommended Posts

Example:

 

I have a table called "discounts" that looks like this:

 

Total

Discount

100

5%

200

7%

300

10%

 

The way it should work is that if someone buys something between 100-199, they'd get the 5% discount, 200-299, the 7% etc.

 

My question is how to I do this without having to have a range-start and range-end field?  I just want to store the range start.

 

I know I could do this easily by doing something like:

 

$total would be a variable amount

SELECT discount FROM discounts WHERE $total >= total ORDER BY total DESC LIMIT 1 

 

That seems like a hack for some reason.  Is there a more "proper" way to do this.

 

Link to comment
https://forums.phpfreaks.com/topic/41332-help-with-query-ranges/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.