<?php
$region=$_GET['region'];
$data = array();
require 'config.php';
$sql= "select * from ksa where region=:region";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':region', $region, PDO::PARAM_STR);
$stmt->execute();
$total = $stmt->rowCount();
if($total > 0){
while ($row = $stmt->fetchObject()) {
	
	$male=$row->male;
	$female=$row->female;
	$malepercentage=round((($male/$total)*100),0);
	$femalepercentage=round((($female/$total)*100),0);
	
	$data['status'] = 'ok';
	$data['result'] = array(
          "total" => $row->total,
		  "region" => $row->region,
		  "involuntaryreturns" => $row->involuntaryreturns,
          "male" => $row->male,
	      "female" => $row->female,
		  "malepercentage" =>$malepercentage,
		  "femalepercentage" =>$femalepercentage,
        );
}
}
else if($total == 0){
}
else{
        $data['status'] = 'err';
        $data['result'] = '';
    }
	//returns data as JSON format
    echo json_encode($data);
 ?>