3 Replies - 319 Views - Last Post: 08 January 2013 - 05:36 PM Rate Topic: -----

#1 Rivve  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 25-July 11

Check if date have passed if so change user access

Posted 08 January 2013 - 03:08 PM

Hey guys!

So I've stumbled on a little problem here, or I'm kinda clueless how to achieve it at all.

I'm currently working on a site which will have a premium feature, and they will pay for the features either monthly,annually or yearly. So i realized i have no freakin' idea how to achieve this the most efficient way.
So i got a table named Users
-- Users
-ID
-Username
-Password
-Expires(Date)
-Status(0 or 1(Where 1 = premium)

So i want to check if the expiry date in Expires table have passed, if it has i want it to change Status to zero, and im clueless how to do it.

Any pointers would be awesome i'm sitting here completely clueless.


XoXo,
Rivve

Is This A Good Question/Topic? 0
  • +

Replies To: Check if date have passed if so change user access

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9204
  • View blog
  • Posts: 34,581
  • Joined: 12-June 08

Re: Check if date have passed if so change user access

Posted 08 January 2013 - 03:17 PM

If you are able to check the login you are able to query the database, right? Why not bring back the expiration date and do a compare against today's date? Or compare it against today's date in the query and if the bit says it is invalid then do an update on the status to make it not premium.
Was This Post Helpful? 1
  • +
  • -

#3 Rivve  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 25-July 11

Re: Check if date have passed if so change user access

Posted 08 January 2013 - 03:25 PM

View Postmodi123_1, on 08 January 2013 - 03:17 PM, said:

If you are able to check the login you are able to query the database, right? Why not bring back the expiration date and do a compare against today's date? Or compare it against today's date in the query and if the bit says it is invalid then do an update on the status to make it not premium.


Yeah that made alot of sense, guess i just needed to get it written out for me. Haven't slept in a while almost midnight here aswell so. Alright i'll be getting some work done again then!

Thanks alot, sorry for wasting your time! :)
Was This Post Helpful? 0
  • +
  • -

#4 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,990
  • Joined: 08-June 10

Re: Check if date have passed if so change user access

Posted 08 January 2013 - 05:36 PM

There is really no reason to have the "status" field at all. If you have the expiration date in the database, you can easily determine the status in your queries by comparing it to the current date. All you are doing by storing the "status" is creating the need to update the table when the date expires. - If you are concerned about performance, then don't be. Assuming you use proper date/time field types, a comparison like this is trivial.

Also, on a side-note. You should really try to be more explicit with your names. Using "status" as the name for a Boolean field is extremely unhelpful. You may know it's the status of the premium subscriptions, but it's not at all clear to anybody else. (Or even to you, if you were to come back to this project after a significant break.) - Something like "has_premium" would be better. (I like using "has" or "is" as the start of Boolean fields, but that's just me.)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1