<?php
require_once 'config.php';
//$error=false;
$errors=array();
$cities=array();

$query='SELECT * FROM credit_logs WHERE user_id='.$_GET['user_id'].' ORDER BY id DESC';

$row = mysqli_query($con,$query);
     
    if (mysqli_num_rows($row) >= 1) {
		//$r=mysqli_fetch_array($row)	;
			
		 while($r=mysqli_fetch_array($row)){
		    $category=mysqli_fetch_array(mysqli_query($con,"SELECT * FROM flyers WHERE id=".$r['flyer_id']));
			 $country=mysqli_fetch_array(mysqli_query($con,"SELECT * FROM countries WHERE id=".$category['country_id']));
			$cities[]=['id'=>$r['id'],'user_id'=>$r['user_id'],'flyer_id'=>$r['flyer_id'],'credits'=>$r['credits'],'action'=>$r['action'],'created_at'=>$r['created_at'],'merchant_name'=>$category['merchant_title'],'country_name'=>$country['name']];
			
			
			
		}   
		$errors['earning']=$cities;
		$errors['success']='Transactions data';
    } else {
        
		$errors['success']='There is no Transactions found';
    }
	echo json_encode($errors);
?>