<?php
$data = array();
require 'config.php';
$sql= "
SELECT registration_date, MAX(registration_date) as latest_date, MIN(registration_date) as earliest_date
FROM
(
    SELECT registration_date
    FROM ksa
    UNION ALL
    SELECT registration_date
    FROM ethiopia
) as subQuery
ORDER BY registration_date
";
$stmt = $pdo->prepare($sql);
$stmt->execute();
$total = $stmt->rowCount();
if($total > 0){
while ($row = $stmt->fetchObject()) {
	$edate=$row->earliest_date;
	$ldate=$row->latest_date;
	$e_date = date("M-Y", strtotime($edate));
	$l_date = date("M-Y", strtotime($ldate));
	$data['status'] = 'ok';
	$data['result'] = array(
          "earliest_date" => $e_date,
		  "latest_date" => $l_date,
        );
}
}
else{
        $data['status'] = 'err';
        $data['result'] = '';
    }
	//returns data as JSON format
    echo json_encode($data);
 ?>