<?php
// get these values from your DB.

require_once('config.php');

$error_message;
$valid = true;

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

	

$sql= "select itm_loc.itm_loc_stk_loc, loc_mst_desc, * 
from itm_mst, itm_loc, loc_mst
Where itm_mst.site_cd = itm_loc.site_cd
and itm_loc.site_cd = loc_mst.site_cd
and itm_mst.RowID = itm_loc.mst_rowid
and itm_loc.itm_loc_stk_loc = loc_mst.loc_mst_stk_loc
and itm_mst_stockno = '".$itm_mst_stockno."'
and  itm_mst.site_cd = '".$site_cd."'";

$stmt = sqlsrv_query( $conn, $sql);

if( !$stmt ) {
     $error_message = "Error selecting table (dft_mst)";
	 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) {
	sqlsrv_free_stmt( $stmt);
	sqlsrv_close( $conn);	
	
	returnData($json);	
}

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

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

 
?>