<?php
$region=$_POST['name'];
$data = array();
require 'config.php';
$sql= "select coalesce(sum(total),0) as total from ksa where region=:region";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':region', $region, PDO::PARAM_STR);
$stmt->execute();
while ($row = $stmt->fetchObject()) {
	$total=$row->total;
	
	if($total!=0){
	$total=$row->total;
	$data['status'] = 'ok';
	$data['result'] = array(
          "total" => $row->total,
        );
	}

//else if
else if($total==0){
$sql2= "select coalesce(sum(total),0) as total from ethiopia where region=:region";
$stmt2 = $pdo->prepare($sql2);
$stmt2->bindParam(':region', $region, PDO::PARAM_STR);
$stmt2->execute();
$total2 = $stmt->rowCount();
while ($row = $stmt2->fetchObject()) {
	
	$total=$row->total;	
	$data['status'] = 'ok';
	$data['result'] = array(
          "total" => $row->total,
        );
}
}
//end else if
else{
        $data['status'] = 'err';
        $data['result'] = '';
    }
}
	//returns data as JSON format
    echo json_encode($data);
 ?>