How to sort my problem? PHP

So i have 2 tables tables:

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 :slight_smile:

I hope i explained well what i need :frowning:

I’m not 100% sure what you’re trying to achieve, but couldn’t you do something like:

select * from record inner join rewards on where date > DATE_SUB(NOW(), INTERVAL 24 HOUR) and user = $user

Maybe part of the issue in your original code is that you don’t echo the reward id until after the while() loop to retrieve the results of your first query.

Did you try to echo $reward_row[‘id’]; inside while loop ? You can use print_r($reward_row); inside while loop to see all results.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.