I'm trying to figure out how to code a weekly login rewards and so far I'm a little bit stuck with the current logic I have.
Assuming I have 2 sql tables; 1) for members which has the login session date and 2) for the rewards. So far this is the code I somewhat managed to come up with, and if there is something much better than this, it'll be much highly appreciated. ;__;
// DO CHECK LOGIN
$sql = mysqli_query($connect, "SELECT * FROM `members` WHERE email='$login'");
$row = mysqli_fetch_assoc($sql);
$sql2 = mysqli_query($connect, "SELECT * FROM `rewards` WHERE email='$login'");
$row2 = mysqli_fetch_assoc($sql2);
if ($row2['week'] == 0) {
echo 'This is your first weekly login bonus! Get your rewards below:';
// INSERT REWARD FIRST WEEK
mysqli_query($connect, "UPDATE `rewards` SET `week`='1', `login`='".date('Y-m-d H:i:s')."' WHERE email='$login'");
} else if (($row2['week'] == 1) && (/* $row['session'] is 7 days ahead of $row2['login']*/)) {
echo 'Get your weekly login bonus below.';
// INSERT REWARD SECOND WEEK
mysqli_query($connect, "UPDATE `rewards` SET `week`='2', `login`='".date('Y-m-d H:i:s')."' WHERE email='$login'");
} else if (($row2['week'] == 2) && (/* $row['session'] is 7 days ahead of $row2['login'] (14 days)*/)) {
echo 'Get your weekly login bonus below.';
// INSERT REWARD THIRD WEEK
mysqli_query($connect, "UPDATE `rewards` SET `week`='3', `login`='".date('Y-m-d H:i:s')."' WHERE email='$login'");
} else if (($row2['week'] == 3) && (/* $row['session'] is 7 days ahead of $row2['login'] (21 days)*/)) {
echo 'Get your weekly login bonus below.';
// INSERT REWARD FOURTH WEEK
mysqli_query($connect, "UPDATE `rewards` SET `week`='0', `login`='".date('Y-m-d H:i:s')."' WHERE email='$login'"); // WEEK RESETS FOR NEXT LOGIN
} else {
if ($row2['login'] /* is X days less than $row['session'] */) {
echo 'Your next weekly reward is on [insert date].';
} else if ($row['session'] /* is 8 days more than $row2['login'] */) {
echo 'It seems like you missed a week\'s login. Start over again?';
mysqli_query($connect, "UPDATE `rewards` SET `week`='0', `login`='".date('Y-m-d H:i:s')."' WHERE email='$login'");
}
}
So I'm not entirely sure how I'm gonna execute the commented part of each if-else statement (besides the INSERT REWARD part) because I'm a little bit lost. Many many thanks in advance to those who will be able to help out!