开发者

mysql adjust value temporarily. Is this possible?

I have a module on my website which lists products by their popularity and the list changes quite regularly. I'd like to automatically discount the top 3 popular products, this is easily done through changing the discount column to 5 for the 3rd product 10 for the 2nd and 15 for the top. However, as the list is regularly changing I need this discount id to revert back to whatever it was before it was overwritten with the new discount id.

Would I have to create another column and call it something like old_discount and开发者_如何学Go transfer the old discount to that before changing the new one and then have it copy it back when it is not longer in the top 3?

I'm hoping someone has an easier way this might be done, any help at all would be appreciated. Thanks for your time.


There's probably no way to get around adding something to manage the top three discounts. As far as actual implementation, there's a couple of ways you could do this that come to mind:

  1. Create a table just to store the current list of top 3 products (or a one-row table with three fields for the top three). Refresh this table with the top 3 when you automatically check. Then in your code that calculates prices, reference this table first to see what is being discounted before doing the rest of the calculation.
  2. If you are going to add a column to the table, I would add a temp_discount instead of old_discount so you can always leave the original alone. Then your code should check if temp_discount is set, use that, otherwise use the normal discount column. Then you simply set temp_discount to 0 before setting the next top 3 products every time you want to refresh.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜