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

$site_cd = $_REQUEST['site_cd'];
$wrk_flt_prob_type = $_REQUEST['wrk_flt_prob_type'];

//problemType
$sql= "	SELECT 	wrk_flt.wrk_flt_fault_cd,wrk_flt.column1,  		
				wrk_flt.wrk_flt_prob_grp,wrk_flt.wrk_flt_prob_grp_desc,  		
				wrk_flt.wrk_flt_prob_type,wrk_flt.wrk_flt_prob_type_desc,  	
				wrk_flt.wrk_flt_desc      
		FROM 	wrk_flt  
		WHERE 	wrk_flt.site_cd = '".$site_cd."' 
		AND 	wrk_flt.wrk_flt_disable_flag = '0' 
		AND 	wrk_flt.wrk_flt_prob_type =  '".$wrk_flt_prob_type."'";
$stmt = sqlsrv_query( $conn, $sql);

if( !$stmt ) {
     $error_message = "Error selecting table (problem)";
	 returnError($error_message);
     die( print_r( sqlsrv_errors(), true));
	 
}

$problem = array();

do {
     while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {		
		$problem[] = $row;	
	
     }
} while ( sqlsrv_next_result($stmt) );





if ($valid) {

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

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

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

 
?>