Jump to content

Php Mysql Automation guidance


Go to solution Solved by mac_gyver,

Recommended Posts

Hello everyone

I'm in a pinch on this one. I accepted a job to have some automation. I have to have this run without using cron jobs. I got half of it working, however now I need the other half. I'm not adding any code on this because I'm really just looking for some guidance or examples to learn from, so that I can try to work from there. I cannot seem to find anything from youtube or google that is working for what I'm attempting to do. Here are some details.

Currently, a user can login to their account and see what point level they are in

For example, Sally logs in and she has played a game 20 times. She is now at level 2. There is a display on her profile that says "Sally is at Level 2" (this part I already have working)
Right now, sally can see that she is at level 2 when she logs in because the script counts the amount of times she has played and displays that
NOTE: There are no numbers of such stored (IE: times played as a table). It simply counts the times she has clicked "play" with her unique_id in the database

THE TASK... to have it so Sally gets 1 free play coin on the first of each month because she is in level 2

This can be a button that she clicks to redeem this (which I already know how to create) or it be automatically added (which I don't know how to create)

The problem: I don't know how to make this happen on the first day of each month (even if it's a button to click) and once clicked, then greyed out after redeemed untill the next month on the first day.

What I already know how to do: I can make a button to redeem play coins based on the players level (the calander opperation is where I'm stuck)


Any examples I can learn from would be greatly appreciated. Please remember that a vague website to show bits an pieces wont help me as I still consider myself an amatuer. However something that shows an example or some good explanation of how this can work withOUT it being a cron job is very greatly appreciated.

Thank you for your time :)

Edited by PNewCode
Link to comment
https://forums.phpfreaks.com/topic/317000-php-mysql-automation-guidance/
Share on other sites

on each page request, you would query to find the date (holding the first day of the month) of the last row holding this free-play data for the currently logged in user. if it is older than the start of the current month, you would insert enough rows to get up to the current month.

 

12 minutes ago, PNewCode said:

It simply counts the times she has clicked "play" with her username in the database

you should store related data using the user id (autoincrement primary index in the user table), not the username, so that the username can be edited without needing to go through and update all the related data.

@mac_gyver You are correct with the username. I actually do have it count with a unique_id instead of the username for that very reason. I mis spoke in my original post. I will edit it to that. Thanks for that.
 

35 minutes ago, mac_gyver said:

on each page request, you would query to find the date (holding the first day of the month) of the last row holding this free-play data for the currently logged in user. if it is older than the start of the current month, you would insert enough rows to get up to the current month.

So I found this code. And now what I'm wondering is, is it possible to change this to have it as the first day of each month, and then instead of echo a statement (in this case it is monday) use my function to display the redeem coin button?
I am guessing this is the type of function you were referring to?

 

<?php

$dayofweek = date("w");

switch ($dayofweek) {
  case 1:
    echo "It is Monday";
    break;
}
?>

 

Edited by PNewCode
  • Solution

the date format string to get the first day of the current month is - 'Y-m-01'

you would not write out conditional logic (switch/case, if) for every possible value. if you did have a need to match a set of input values to output values, you would use an array, where the array index is the input value and the stored array value is the output value.

you would display the redeem button based on a non-redeemed status value in the row of data. then update that status value to a redeemed value when the offer is redeemed.

317000 GET

(ahem)

To emphasize what mac_gyver said earlier: you're not running specific logic on specific days. What you should be doing is looking at the current state of things (like the date) and comparing with the previous state of things (like when The Thing last happened) and figuring out what to do.
If you want to give the user the option to do something "on the first of the month" then the current state is the date, the previous state is the last time the user exercised the option, and the comparison is whether it's now a new month since then. If the current month is June 2023 and the user did the thing in May, or April, or March, then you let them do the thing; if they did the thing in June (ie. this month) then you don't let them do the thing.
If you wanted to give them the option every month with rollover, you do the exact same thing except the comparison is "how many months have lapsed since they did the thing". If they did the thing in March then you would grant them 3 (April, May, June) options.

@requinix and @mac_gyver thank you very much. Between the two of you I was able to learn from it and make this function work. I made a string to specify if it was the first day of the month and IF it was then it would send the command and specified an if for the count (shown below) and put a separate php code as an include to add to the count as needed.
I know the below is kind of vague, but I have 2 different files working this and didn't want to clutter the post up too much. But it was the advice of the 2 of you that made it work. Thank you very much


$usertotal = number_format($num_rows['count'] > 0 and $num_rows['count'] < 49);
//// add to user totals function here based on the level then display the next level ////

if ( $num_rows['count'] > 0 and $num_rows['count'] < 49 ) {
echo "


<font color='lightblue' face='Verdana, Arial, Helvetica, sans-serif' size='4'>Next Play Level For You Is <font color='#CC9966' face='Verdana, Arial, Helvetica, sans-serif' id='levelcolor'>BRONZE</font><font color='#cccccc' face='Verdana, Arial, Helvetica, sans-serif' size='4'><br><i>(50-99 requests made)</i></font>";
}

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.