<?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 outEasily 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.")"); } ?>
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.")"); } ?>
DATE(`daily_time`) <= CURRENT_DATE - INTERVAL 23 HOUR
PM'dIf 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.PHP:DATE(`daily_time`) <= CURRENT_DATE - INTERVAL 23 HOUR
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_
You must be registered for see links