<?php

require_once __DIR__ . '/db_config.php';

$response = array();
$response["clients"] = array();

if (isset($_POST["cname"]) ) {
 
$cname=$_POST["cname"];
$id=$_POST["id"];

$con = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD,DB_DATABASE) or die(mysql_error());


$clientQuery="SELECT c_created_by_id AS cby,c_created_by_type as cbytype,c_datetime AS ccreateddatetime,c_company_id as cid,c_company_name as cname,c_responsible_person as rperson,c_responsible_mobile as rpersonmobile,c_responsible_mailid as remail,c_company_address as caddress,c_company_mobile  AS cmobile,c_company_mailid as cemail,c_company_phone as cphone,c_company_address as cweb FROM task_client_company WHERE c_companyname='$cname' ";

if(!empty($id)){
  $clientQuery=$clientQuery." AND c_company_id='$id'";
}


$clinetResult=mysqli_query($con,$clientQuery);
if(!empty($clinetResult) && mysqli_num_rows($clinetResult) > 0){
    while ($row = mysqli_fetch_array($clinetResult,MYSQLI_ASSOC)) {
        array_push($response["clients"], $row);
    }
}
    mysqli_close($con);

}

echo json_encode($response);


?>