I am using the code below to show ads to my users. Once any user has clicked on one add, it should not appear to the same user within 24 hours.
$sql2=$Db1->query("SELECT * FROM ads2 WHERE active='1' ORDER BY RAND()");
while($temp=$Db1->fetch_array($sql2)) {
$sql=$Db1->query("SELECT * FROM ads2_log WHERE user='$username' AND target='{
$temp['target']}' AND shorten='{$temp['shorten']}' ORDER BY fecha DESC");
$row=$Db1->fetch_array($sql);
$showads = true;
if( $row['fecha'] != "" ){
$hourdiff = round(($row['fecha'] - time())/3600, 1);
//echo "Last click: ".date("Y/m/d H:i:s", $row['fecha'])." - ".$hourdiff;
if( $hourdiff < 24 ) { $showads = false; }
}
if( $showads == true )
{
But in my case it's not working for me.