<?php
$start_date=$_POST['start_date'];
$end_date=$_POST['end_date'];
$center=$_POST['center'];
    include 'config.php';
	$sth = mysqli_query($con,"SELECT region,sum(total) as total from mrcs  where center='$center' and registration_date between '$start_date' and '$end_date' group by region order by total desc limit 3");
    $rows = array();
    $rows['name'] = 'Region';
    while($r = mysqli_fetch_array($sth)) {
     $rows['data'][] = $r['region'];
    }
    $sth = mysqli_query($con,"SELECT sum(total) as total from mrcs where center='$center' and registration_date between '$start_date' and '$end_date' group by region order by total desc limit 3");
    $rows1 = array();
    $rows1['name'] = 'Migrants';
	$rows1['color'] = '#0033a1';
    while($rr = mysqli_fetch_array($sth)) {
     $rows1['data'][] = $rr['total'];
    }
	$result = array();
    array_push($result,$rows);
    array_push($result,$rows1);
    print json_encode($result, JSON_NUMERIC_CHECK);
    mysqli_close($con);
    ?>