Jump to content

Use last login as a condition - how?


Terminaxx

Recommended Posts

Hey guys,

 

I am trying to create a cronjob, which changes the value of a table column from every user daily. That is not the problem.

 

My question is, how can I set that if a user has not logged in for more than 10 days, the cronjob doesnt affect him?

 

 

Thanks for any help

Link to comment
Share on other sites

I assume you're storing logins somewhere. You could use that information to retrieve a list of "eligible" users on whom to perform whatever action your cron job is meant to perform.

Not sure what you mean. I would also like to make it work automatically because the database will have many users.

 

Could you explain it more specific?

Link to comment
Share on other sites

Sounds like your cron job is just executing some SQL query based on what little information you provided in your original post. If that's an incorrect assumption, can you flesh out what it is you're actually doing? If I'm right, then you could either use last login date/time as a constraint in your update, or use it to select the correct set of users and then perform whatever actions you need to individually.

Link to comment
Share on other sites

My guess is that you are making things more difficult than they need to be. I'm curious what value you are changing and why. In the vast majority of instances business rules can be performed in "real time" without needing to reset data. As to your question, just put a caluse on the update query to not perform the change to users based on thier login date

 

 

UPDATE table_name
SET some_field = :new_value
WHERE last_login > DATE_SUB(NOW(), INTERVAL 10 DAY) 
Link to comment
Share on other sites

 

My guess is that you are making things more difficult than they need to be. I'm curious what value you are changing and why. In the vast majority of instances business rules can be performed in "real time" without needing to reset data. As to your question, just put a caluse on the update query to not perform the change to users based on thier login date

UPDATE table_name
SET some_field = :new_value
WHERE last_login > DATE_SUB(NOW(), INTERVAL 10 DAY) 

 

Every user has points, which they can earn by doing diffrent things. I want to give them interest (do you say it like that in english?) every week. It works just fine. But I dont want to give people interest, when they dont login.

Link to comment
Share on other sites

Every user has points, which they can earn by doing diffrent things. I want to give them interest (do you say it like that in english?) every week. It works just fine. But I dont want to give people interest, when they dont login.

That's a reasonable use of a cron job. Were you able to implement the restriction based on login date as I showed in the example?

Link to comment
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.