I have a website that let users download PDF files,
I made a download limit 10 files per day for each user and I stored the numbers inside MySQL database. everything works great!
The problem is: The limit will be set forever, I want it to reset to 0 each 24h.
Is there any phpmyadmin command or something to reset that column each 24h to 0 automatically or any other way!
2
Answers
I would try a different way.
I would add table download_log(user_id, file_id, timestamp) and insert row every time user downloads some file.
To check if user reached limit you can check how many downloads he did perform in last 24h.
Something like
To schedule some operations you can use cron to run script
It looks like you are already storing the download counts in a log table of sorts.
For expiring those counts, I suggest using the event scheduler native to MySQL. You may need to enable it in your server parameters.
Syntax would look something like this: