SQL/phpMyAdmin - Create a row with a value and reset that value every 24 hours with an event










0














I'm creating a feature for my site which allows users to make up to 5 posts per day. I need to create a row in my users database with the value 5 that is subtracted 1 each time a user makes a post. I will subtract 1 from this value using PHP when the user makes a post, and then when it reaches 0 the user wont be allowed to make another post. I don't need help with that part. But I need help on how to reset this counter value every day at 12:00 am using an event on the database level. I'm no database expert and so I have two questions:



  1. What should the Type, Length/Values, Default, Collation, Attributes, etc be for this counter value? I was thinking Int, 5, and nothing else. What should it be? It is simply a counter value that starts at 5 and is subtracted 1 for each post made, and it won't be anything less than 0.


  2. What is the proper definition for the database event to reset this counter value every 24 hours? I'm missing a few fields for the event, but this is what I have so far:


Status: ENABLE



Event type: RECURRING



Execute every: 1 DAY



Start: ???



End: ???



Definition: ???



On complete preserve: ???



Definer: ???



Comment: ???










share|improve this question



















  • 1




    Why not query your post table for that user for the day to see they haven't exceeded their daily maximum? Would be a lot more flexible if/when the daily maximums change or if you want those limits to change based on the user.
    – msturek
    Nov 8 '18 at 21:00















0














I'm creating a feature for my site which allows users to make up to 5 posts per day. I need to create a row in my users database with the value 5 that is subtracted 1 each time a user makes a post. I will subtract 1 from this value using PHP when the user makes a post, and then when it reaches 0 the user wont be allowed to make another post. I don't need help with that part. But I need help on how to reset this counter value every day at 12:00 am using an event on the database level. I'm no database expert and so I have two questions:



  1. What should the Type, Length/Values, Default, Collation, Attributes, etc be for this counter value? I was thinking Int, 5, and nothing else. What should it be? It is simply a counter value that starts at 5 and is subtracted 1 for each post made, and it won't be anything less than 0.


  2. What is the proper definition for the database event to reset this counter value every 24 hours? I'm missing a few fields for the event, but this is what I have so far:


Status: ENABLE



Event type: RECURRING



Execute every: 1 DAY



Start: ???



End: ???



Definition: ???



On complete preserve: ???



Definer: ???



Comment: ???










share|improve this question



















  • 1




    Why not query your post table for that user for the day to see they haven't exceeded their daily maximum? Would be a lot more flexible if/when the daily maximums change or if you want those limits to change based on the user.
    – msturek
    Nov 8 '18 at 21:00













0












0








0







I'm creating a feature for my site which allows users to make up to 5 posts per day. I need to create a row in my users database with the value 5 that is subtracted 1 each time a user makes a post. I will subtract 1 from this value using PHP when the user makes a post, and then when it reaches 0 the user wont be allowed to make another post. I don't need help with that part. But I need help on how to reset this counter value every day at 12:00 am using an event on the database level. I'm no database expert and so I have two questions:



  1. What should the Type, Length/Values, Default, Collation, Attributes, etc be for this counter value? I was thinking Int, 5, and nothing else. What should it be? It is simply a counter value that starts at 5 and is subtracted 1 for each post made, and it won't be anything less than 0.


  2. What is the proper definition for the database event to reset this counter value every 24 hours? I'm missing a few fields for the event, but this is what I have so far:


Status: ENABLE



Event type: RECURRING



Execute every: 1 DAY



Start: ???



End: ???



Definition: ???



On complete preserve: ???



Definer: ???



Comment: ???










share|improve this question















I'm creating a feature for my site which allows users to make up to 5 posts per day. I need to create a row in my users database with the value 5 that is subtracted 1 each time a user makes a post. I will subtract 1 from this value using PHP when the user makes a post, and then when it reaches 0 the user wont be allowed to make another post. I don't need help with that part. But I need help on how to reset this counter value every day at 12:00 am using an event on the database level. I'm no database expert and so I have two questions:



  1. What should the Type, Length/Values, Default, Collation, Attributes, etc be for this counter value? I was thinking Int, 5, and nothing else. What should it be? It is simply a counter value that starts at 5 and is subtracted 1 for each post made, and it won't be anything less than 0.


  2. What is the proper definition for the database event to reset this counter value every 24 hours? I'm missing a few fields for the event, but this is what I have so far:


Status: ENABLE



Event type: RECURRING



Execute every: 1 DAY



Start: ???



End: ???



Definition: ???



On complete preserve: ???



Definer: ???



Comment: ???







sql database events






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 '18 at 2:44









Isaac Bennetch

7,73121629




7,73121629










asked Nov 8 '18 at 20:30









Chris Johnson

96




96







  • 1




    Why not query your post table for that user for the day to see they haven't exceeded their daily maximum? Would be a lot more flexible if/when the daily maximums change or if you want those limits to change based on the user.
    – msturek
    Nov 8 '18 at 21:00












  • 1




    Why not query your post table for that user for the day to see they haven't exceeded their daily maximum? Would be a lot more flexible if/when the daily maximums change or if you want those limits to change based on the user.
    – msturek
    Nov 8 '18 at 21:00







1




1




Why not query your post table for that user for the day to see they haven't exceeded their daily maximum? Would be a lot more flexible if/when the daily maximums change or if you want those limits to change based on the user.
– msturek
Nov 8 '18 at 21:00




Why not query your post table for that user for the day to see they haven't exceeded their daily maximum? Would be a lot more flexible if/when the daily maximums change or if you want those limits to change based on the user.
– msturek
Nov 8 '18 at 21:00












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53215693%2fsql-phpmyadmin-create-a-row-with-a-value-and-reset-that-value-every-24-hours-w%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53215693%2fsql-phpmyadmin-create-a-row-with-a-value-and-reset-that-value-every-24-hours-w%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo