So i have 2 tables tables:
Rewards
id and value
and records (lets call the reward claims)
id, claimId ( this is rewards id), date (datetime 2017-05.02 16:03:13)
what i want do do is:
select for each claimId select last date if there is some and know have 24 hrs has been elapsed and return random claimId
i tried multiple queries but failed to return real result
Here is what i got now:
$checkRecords = mysqli_query($conn, "SELECT * FROM record WHERE date > DATE_SUB(NOW(), INTERVAL 24 HOUR) AND user='".$user."'") or die(mysqli_error($conn));
while($check_row = mysqli_fetch_array($checkRecords)){
$getRewards = mysqli_query($conn, "SELECT id FROM rewards WHERE id='".$check_row['claimId']."' ORDER BY RAND() LIMIT 1") or die(mysqli_error($conn));
$reward_row = mysqli_fetch_array($getRewards);
}
echo $reward_row['id'];
and that echo should show unique random id that has been taken more that 24 hrs ago
So what am i doing wrong?
Any help is needed
I hope i explained well what i need