<?php
 

    // array for JSON response
    $response= array();
    // include db connect class
    require_once __DIR__ . '/../DBConnect.php';
    
    if (isset($_POST['ClientID'])) {
      $ClientID = $_POST['ClientID'];
	    try {
        	 $sql = "SELECT * FROM Account2Group WHERE ClientID = $ClientID";
        	$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
        	$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        	$stmt = $conn->prepare($sql);
        	$stmt->execute();
        	$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
        	
            if($result!=null &&  $result>0){
        		 $response["Account2Group"] = array();
        		 
        		 foreach($result as $row) { 
            	      $Account2Group["AcGroupID"] = $row["AcGroupID"];
                      $Account2Group["AcTypeID"] = $row["AcTypeID"];
                      $Account2Group["AcGruopName"] = $row["AcGruopName"];
                      $Account2Group["ClientID"] = $row["ClientID"];
                      $Account2Group["ClientUserID"] = $row["ClientUserID"];
                      $Account2Group["SysCode"] = $row["SysCode"];
                      $Account2Group["NetCode"] = $row["NetCode"];
                      $Account2Group["UpdatedDate"] = $row["UpdatedDate"];
                      // push single product into final response array
                      array_push($response["Account2Group"], $Account2Group);
        		}
    		    // success
        		$response["success"] = 1;
        		// echoing JSON response
        		echo json_encode($response);
        	}
        	else{	
        	    // success
        		$response["success"] = 0;
        		$response["message"] = "No Data Availaible";
        	    // echoing JSON response
        		echo json_encode($response);
    		}
    	}
    	catch(PDOException $e){
    		echo "Error: " . $e->getMessage();
    	}
        $conn = null; 
    }else {
        // success
        $response["success"] = 0;
        $response["message"] = "Set All Parameter";
        // echoing JSON response
		echo json_encode($response);
    }
?>
