Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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