<?php
require_once "../magic/DataBase.php";
 $database = new DataBase();

  $conn = $database->getConnection();
  
if(isset($_POST["maxkm"]))
{
	$idd = $_POST["maxkm"] ;
	$output = array();
	$sql = $conn->prepare("SELECT km_in FROM contracts
    WHERE contract_id = (select contract_id from car_contracts where date_in = (select max(date_in) from car_contracts WHERE carid = ?) ) ");
	$sql->bindParam(1,$idd);
	$sql->execute();
  if($sql->rowCount()>0){$row = $sql->fetch(PDO::FETCH_ASSOC);
		$maxkm	= $row["km_in"];
  }
  if(empty($maxkm)){$maxkm = 0 ;}
  echo $maxkm;
}
?>
