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

$query="SELECT * FROM points_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)){
			 
			 $level=0;
	$credits=$r['credits'];
	if($credits<=1000){
		$level=1;
	}elseif($credits<=50000 && $credits>1000){
		$level=2;
	}elseif($credits<=100000 && $credits>50000){
		$level=3;
	}elseif($credits<=1000000 && $credits>100000){
		$level=4;
	}
			 $cat=mysqli_fetch_array(mysqli_query($con,"SELECT * FROM users WHERE id=".$r['user_id']));
			 
			$cities[]=['logid'=>$r['id'],'user_id'=>$r['user_id'],'level'=>'Level '.$level,'Availablepoints'=>$r['points'],'Earningpoints'=>$r['points'],'difference'=>$r['difference'],'type'=>'RLS','date'=>$r['created_at']];
			
			
			
		}   
		$errors['pointlog']=$cities;
		
		$errors['success']='Points log history data';
    } else {
        
		$errors['success']='There is no log found';
    }
	echo json_encode($errors);
?>