In no way can I formulate a query to the database, so that all entries that have dates (payment date) older than a month are replaced in the field status = 'inactive' . Something like this: UPDATE table SET status = 'inactive' WHERE dates <= DATE_SUB(CURDATE(), INTERVAL 1 MONTH); but I have dates in INT(11) in unix.

  • About the update. The answer to the first question - in the second question, only I was wrong with the numbers. This query updates the paid field in the user table. If the current time minus the time that is already recorded in this field is less than a month (i.e. the Expert mode is still valid), we write the remainder + current time = previous_time_time + 2 * month . If more, i.e. Now free mode, then just write the current time. - Sergiks 5:56 pm
  • Math drives many into paint:) We mark the beginning of the paid period. Twice paid = 2 months from the first payment. - Sergiks
  • I can not formulate a query to the database in any way so that all records with dates (payment date) older than a month are replaced in the status = 'inactive' field. Something like this: UPDATE table SET status = 'inactive' WHERE dates <= DATE_SUB (CURDATE (), INTERVAL 1 MONTH); But I have dates in INT (11) in UNIX. - Batyabest

2 answers 2

Instead of 1/0, store the timestamp in the DB of the moment when the user became an Expert.

Simply newbies have 0 there by default. When the user logs in, compare the current time() with the value from the database. If less than a month has passed ( 31*24*60*60 seconds), consider the user an Expert. Otherwise - Newbie.

  • I need to tie up the payment here. Is this method suitable? That is, people paid, a month later, his "subscription" ended. Plus, the status must be displayed in words in the user profile and other pages of the site. - Batyabest
  • one
    Of course, it fits: payment has come - the current date-time has been assigned to the user in the DB field. He himself recently did so. Consider another moment of conflict: can pay before the expiration of the current payment. Or immediately pay for 2 months. Then you need to calculate the unused remainder of time and add it to the current time, before writing to the database. - Sergiks
  • I think, conflicts with payment for 2 months can be avoided by registering a fixed amount in the payment field (the same robocash desk). But with prepay ahead of time, yes ... Maybe the trouble ... I think that the value can be updated in the database for the current one, but then "unused days" will burn. How to be? - Batyabest
  • one
    How do you distinguish between users - do they somehow log in? Here at this stage and their status check / install. With payment before the time I wrote. Something like this: UPDATE users SET paid = IF ((UNIX_TIMESTAMP () - paid) <67685760, paid + 135371520, UNIX_TIMESTAMP ()) - Sergiks
  • one
    Instead of a timestamp, make the field Int (11) - Sergiks

Watch these videos - Download (.zip) and Create Automated Queries in MySQL