Terminaxx Posted April 20, 2017 Share Posted April 20, 2017 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 Quote Link to comment https://forums.phpfreaks.com/topic/303758-use-last-login-as-a-condition-how/ Share on other sites More sharing options...
dkub Posted April 20, 2017 Share Posted April 20, 2017 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. Quote Link to comment https://forums.phpfreaks.com/topic/303758-use-last-login-as-a-condition-how/#findComment-1545668 Share on other sites More sharing options...
ginerjm Posted April 20, 2017 Share Posted April 20, 2017 Use a database entry? Quote Link to comment https://forums.phpfreaks.com/topic/303758-use-last-login-as-a-condition-how/#findComment-1545669 Share on other sites More sharing options...
Terminaxx Posted April 20, 2017 Author Share Posted April 20, 2017 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? Quote Link to comment https://forums.phpfreaks.com/topic/303758-use-last-login-as-a-condition-how/#findComment-1545684 Share on other sites More sharing options...
dkub Posted April 20, 2017 Share Posted April 20, 2017 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. Quote Link to comment https://forums.phpfreaks.com/topic/303758-use-last-login-as-a-condition-how/#findComment-1545685 Share on other sites More sharing options...
Solution Psycho Posted April 20, 2017 Solution Share Posted April 20, 2017 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) Quote Link to comment https://forums.phpfreaks.com/topic/303758-use-last-login-as-a-condition-how/#findComment-1545686 Share on other sites More sharing options...
Terminaxx Posted April 20, 2017 Author Share Posted April 20, 2017 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. Quote Link to comment https://forums.phpfreaks.com/topic/303758-use-last-login-as-a-condition-how/#findComment-1545695 Share on other sites More sharing options...
Psycho Posted April 20, 2017 Share Posted April 20, 2017 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? Quote Link to comment https://forums.phpfreaks.com/topic/303758-use-last-login-as-a-condition-how/#findComment-1545712 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.