<?php
// get these values from your DB.
require_once('config.php');
$error_message;
$valid = true;

$site_cd = $_REQUEST['site_cd'];
$ast_dwntime_asset_no = $_REQUEST['ast_dwntime_asset_no'];
$ast_dwntime_down_wo = $_REQUEST['ast_dwntime_down_wo'];

//Chargeable
$sql="	select	ast_dwntime_down_wo
		From	ast_dwntime 
		Where	ast_dwntime_asset_no = '".$ast_dwntime_asset_no."' 
		And		site_cd = '".$site_cd."' 
		and		ast_dwntime_down_wo <> '".$ast_dwntime_down_wo."' 
		And		ast_dwntime_up_wo IS NULL
		And		ast_dwntime_down_wo IS NOT NULL";
		
$stmt = sqlsrv_query( $conn, $sql);

if( !$stmt ) {
     $error_message = "Error selecting table (ast_dwntime)";
	 returnError($error_message);
     die( print_r( sqlsrv_errors(), true));
	 
}
$json= array();
do {
     while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {	
	 
		$json[] = $row;		
	
     }
} while ( sqlsrv_next_result($stmt) );


if ($valid) {

	//echo $sql;
	returnData($json);	
	
}

function returnData($json){
	$returnData = array(
	'status' => 'SUCCESS',
	'message' => 'Successfully',	
	'data' =>$json);
	
	echo json_encode($returnData);	
}

function returnError($error_message){
	$json = array();
	
	$returnData = array(
	'status' => 'ERROR',
	'message' => $error_message,
	'data' => '');
	
	echo json_encode($returnData);
		
}
	sqlsrv_free_stmt( $stmt);
	sqlsrv_close( $conn);	

 
?>