<?php
ob_start();
include("../connect.php");
$response=array();
if(isset($_POST['distributor_id']))
{ 
    $d_id = $_POST['distributor_id']; 
	$res = mysqli_query($con,"SELECT category_name FROM tbl_master_category where distributor_id='$d_id' and status='Active' group by category_name");
	if(mysqli_num_rows($res)>0) 
	{	
		$categorys=array();
		while($row=mysqli_fetch_array($res))
		{  
			$category['category_name'] = $row['category_name'];
			$my_category=$row['category_name'];
			$res1 = mysqli_query($con,"SELECT tbl_master_category.category_id,tbl_master_brand.brand_id,tbl_master_brand.brand_name FROM tbl_master_category,tbl_master_brand where tbl_master_category.brand_id=tbl_master_brand.brand_id and  tbl_master_category.category_name='$my_category'");
			$category['brands']=array();
			while($row1=mysqli_fetch_array($res1))
			{
				$brand['category_id'] = $row1['category_id'];
				$brand['brand_id'] = $row1['brand_id'];
				$brand['brand_name'] = $row1['brand_name'];
				$category['brands'][]=$brand;		
			}
			$response['categorys'][]=$category;	
		}
	   $response['success']=1;
	   $response['details']="Brand Category Detail Fetched Successfully";  
	}
    else
	{
		$response['success']=0;
		$response['details']="Brand Category Not Available...!!";
	} 
	$response['app_version']='1.3';
}
else
{	
	$response['success']=0;
	$response['details']="Required fields missing";
}
echo json_encode($response);
?> 