<?php
$start_date=$_GET['start_date'];
$end_date=$_GET['end_date'];
$region=$_GET['region'];
$data = array();
require 'config.php';
$sql= "select region,coalesce(sum(total),0) as total,coalesce(sum(male),0) as male,coalesce(sum(female),0) as female,coalesce(sum(minors),0) as minors,coalesce(sum(children_male),0) as children_male,coalesce(sum(children_female),0) as children_female,coalesce(sum(involuntaryreturns),0) as involuntaryreturns from ksa where region=:region and registration_date between :start_date and :end_date";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':region', $region, PDO::PARAM_STR);
$stmt->bindParam(':start_date', $start_date, PDO::PARAM_STR);
$stmt->bindParam(':end_date', $end_date, PDO::PARAM_STR);
$stmt->execute();
$total = $stmt->rowCount();
if($total > 0){
while ($row = $stmt->fetchObject()) {
	
	$data['status'] = 'ok';
	$data['result'] = array(
          "total" => $row->total,
		  "region" => $row->region,
		  "minors" => $row->minors,
          "involuntaryreturns" => $row->involuntaryreturns,
        );
}
}
else{
        $data['status'] = 'err';
        $data['result'] = '';
    }
	//returns data as JSON format
    echo json_encode($data);
 ?>