dooo61733 2014-03-21 02:55
浏览 13
已采纳

将用户帐户设置为在给定时间后过期[关闭]

The users table in a database has the following fields(among others):

  • date created (the date when the user has joined)
  • confirmed (set to 1 if the user has confirmed his email)
  • approved (set to 1 if the user has beed approved by the admin)

What I would like to do is to create another row, called "period" which will be updated to 1 if the user wants to join for 1 month, 2 if he wants to join for 6 months, and 3 if he wants to join for 1 year

I wonder if it is possible to somehow automatically set the approved from 1 to 0 after the chosen period has expired. I am just asking for some ideas... I hope that after reading your opinions I might come with the best solution in my particular case....

how would you aproach such an issue?

  • 写回答

2条回答 默认 最新

  • dongpang1898 2014-03-21 02:59
    关注

    The best way to do this is with a view. You can compare the current time to the end time for the subscription:

    create view v_users as
        select u.*,
               (now() < (datecreated + interval (case when period = 1 then 1
                                                      when period = 2 then 6
                                                      when period = 3 then 12
                                                  end) month
                        )
               ) as approved
        from users u;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致