Adding a gift reward to the CMS [Help REQUEST]

Sly

I don't break the rules I bend them.
Oct 28, 2016
246
38
Good evening ladies & gents. I am struggling with a problem.. I want to add a gift reward button in my CMS, so that every 24-hr when users click it, I want them to gain an item or credits to my choice.

Any known tutorials?
 

JMS

Posting Freak
Aug 25, 2014
562
270
Easily done, with a PHP Script. You'd need to use the use of timestamps if you wanted it to be dynamic timings, so 24 hours from when the user last opens it. Although, the easier option would be too set the date yourself, so its a daily reward. I'll include an example of how it was done on Pure for the advent, the script wont work for you, but it'll give you a good idea on how too start.

PHP:
<?php
date_default_timezone_set("GMT");
$day = 2; //Used mainly for advent purposes
$user = mysql_query("SELECT * FROM users WHERE id = ".$_SESSION['user']['id']);
$advent = mysql_query("SELECT * FROM advent WHERE user_id = ".$_SESSION['user']['id']." AND `day` =".$day);
if (mysql_num_rows($advent) > 0){
    echo "You've already collected this gift!"; //
} else {
    echo "You've been given 5000 credits!";
    mysql_query("UPDATE users SET credits = credits + 5000 WHERE id = ".$user['id']);
    mysql_query("INSERT INTO advent (id, user_id, `day`) VALUES (null,".$user['id'].",".$day.")");
}
?>
 

Sly

I don't break the rules I bend them.
Oct 28, 2016
246
38
Easily done, with a PHP Script. You'd need to use the use of timestamps if you wanted it to be dynamic timings, so 24 hours from when the user last opens it. Although, the easier option would be too set the date yourself, so its a daily reward. I'll include an example of how it was done on Pure for the advent, the script wont work for you, but it'll give you a good idea on how too start.

PHP:
<?php
date_default_timezone_set("GMT");
$day = 2; //Used mainly for advent purposes
$user = mysql_query("SELECT * FROM users WHERE id = ".$_SESSION['user']['id']);
$advent = mysql_query("SELECT * FROM advent WHERE user_id = ".$_SESSION['user']['id']." AND `day` =".$day);
if (mysql_num_rows($advent) > 0){
    echo "You've already collected this gift!"; //
} else {
    echo "You've been given 5000 credits!";
    mysql_query("UPDATE users SET credits = credits + 5000 WHERE id = ".$user['id']);
    mysql_query("INSERT INTO advent (id, user_id, `day`) VALUES (null,".$user['id'].",".$day.")");
}
?>
Cheers JMS, will get back to you once I've sorted this out
 

MayoMayn

BestDev
Oct 18, 2016
1,423
683
Easily done, with a PHP Script. You'd need to use the use of timestamps if you wanted it to be dynamic timings, so 24 hours from when the user last opens it. Although, the easier option would be too set the date yourself, so its a daily reward. I'll include an example of how it was done on Pure for the advent, the script wont work for you, but it'll give you a good idea on how too start.

PHP:
<?php
date_default_timezone_set("GMT");
$day = 2; //Used mainly for advent purposes
$user = mysql_query("SELECT * FROM users WHERE id = ".$_SESSION['user']['id']);
$advent = mysql_query("SELECT * FROM advent WHERE user_id = ".$_SESSION['user']['id']." AND `day` =".$day);
if (mysql_num_rows($advent) > 0){
    echo "You've already collected this gift!"; //
} else {
    echo "You've been given 5000 credits!";
    mysql_query("UPDATE users SET credits = credits + 5000 WHERE id = ".$user['id']);
    mysql_query("INSERT INTO advent (id, user_id, `day`) VALUES (null,".$user['id'].",".$day.")");
}
?>
PHP:
 DATE(`daily_time`) <= CURRENT_DATE - INTERVAL 23 HOUR
If you want it to be daily @Sly, and reset at a new day (00:00) this is how I did it, the reason I made it 23 hours and not 24 hours, depends on the local time of the user and the mysql.
And another thing, @JMS, there's no reason at all to use "*" when the only think you're fetching from the table is "id", which will just make the query slower. You don't really need to brag about anything, if you don't even know such simple details.
PM me @Sly, and I will provide a full daily reward function with sql, with different items based on the probability of receiving them, you will just have to convert it from PDO to mysql_
 
Last edited:

Sly

I don't break the rules I bend them.
Oct 28, 2016
246
38
PHP:
 DATE(`daily_time`) <= CURRENT_DATE - INTERVAL 23 HOUR
If you want it to be daily @Sly, and reset at a new day (00:00) this is how I did it, the reason I made it 23 hours and not 24 hours, depends on the local time of the user and the mysql.
And another thing, @JMS, there's no reason at all to use "*" when the only think you're fetching from the table is "id", which will just make the query slower. You don't really need to brag about anything, if you don't even know such simple details.
PM me @Sly, and I will provide a full daily reward function with sql, with different items based on the probability of receiving them, you will just have to convert it from PDO to mysql_
PM'd
 
Still need help in this case, as I am still struggling adding a gift reward in the CMS
 

Users who are viewing this thread

Top