<?php
include "../connection/config.php";
extract($_REQUEST);
date_default_timezone_set("Asia/Kolkata");
$date=strtotime(date('Y-m-d', strtotime('-6 days')));

if(isset($_REQUEST['date'])){
    
$sx = query("SELECT * FROM `games` where user='$mobile' AND date='".$_REQUEST['date']."' order by created_at desc");
} else {
    
$sx = query("SELECT * FROM `games` where user='$mobile' and created_at > '$date' order by created_at desc");
}

while($x = fetch($sx))
{
    $x['date'] = date('d M Y h:i A',$x['created_at']);
    $data['data'][] = $x;
}

if(isset($_REQUEST['date'])){
    
$sx = query("SELECT * FROM `starline_games` where user='$mobile' AND date='".$_REQUEST['date']."' order by created_at desc");
} else {
    
$sx = query("SELECT * FROM `starline_games` where user='$mobile' order by created_at desc");
}

while($x = fetch($sx))
{
    $x['date'] = date('d M Y h:i A',$x['created_at']);
    $x['bazar'] = $x['bazar'].' '.$x['timing_sn'];
    $data['data'][] = $x;
}

function date_compare($a, $b)
{
    $t1 = $a['created_at'];
    $t2 = $b['created_at'];
    $r = $t1 - $t2;
  if($r < 0){ return 1; } else {
     return -1;
  }
}    
usort($data['data'], 'date_compare');

echo json_encode($data);