<?php

require_once __DIR__ . '/db_config.php';

$response = array();
$response["categories"] = 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());


$catQuery="SELECT cat_id as catid,task_categoryname as catname,cat_description as catdescription,cat_created_by_mailid as catby,cat_created_by_type as catbytype,cat_datetime as catcreateddatetime FROM task_category WHERE cat_companyname='$cname' ";

if(!empty($id)){
  $catQuery=$catQuery." AND cat_id='$id'";
}


$catResult=mysqli_query($con,$catQuery);
if(!empty($catResult) && mysqli_num_rows($catResult) > 0){
    while ($row = mysqli_fetch_array($catResult)) {
        array_push($response["categories"], $row);
    }
}

mysqli_close($con);
}

echo json_encode($response);


?>