<?php
ob_start();
include("../connect.php");
$response=array();
if(isset($_POST['distributor_id']))
{ 
    $d_id = $_POST['distributor_id']; 
	
	
	$res = mysqli_query($con,"SELECT * FROM tbl_master_brand where distributor_id='$d_id'");
	$row=mysqli_num_rows($res);
	if($row>0) 
	{	
      $brands=array();
       while($row=mysqli_fetch_array($res))
	   {  
          $brand['brand_id'] = $row['brand_id'];
		  $brand['brand_name'] = $row['brand_name'];
		  $b_id=$row['brand_id'];
		  
		  
		  $res1 = mysqli_query($con,"SELECT * FROM tbl_master_category where brand_id='$b_id'");
          $brand['categories']=array();
		   while($row1=mysqli_fetch_array($res1))
		   {
			$category['category_id'] = $row1['category_id'];
			$category['category_name'] = $row1['category_name'];
            $brand['categories'][]=$category;		
		   }
		   
		  $response['brands'][]=$brand;	   
	   }

	   $response['success']=1;
	   $response['details']="Brand Category Detail Fetched Successfully";  
	}
    else
	{
		$response['success']=0;
		$response['details']="Brand Category Not Available...!!";
	} 
}
else
{	
	$response['success']=0;
	$response['details']="Required fields missing";
}
echo json_encode($response);
?> 