<?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_category where distributor_id='$d_id'");
	$row=mysqli_num_rows($res);
	if($row>0) 
	{	
      $brands=array();
       while($row=mysqli_fetch_array($res))
	   {  
          $brand['category_id'] = $row['category_id'];
		  $brand['category_name'] = $row['category_name'];
		  $b_id=$row['category_id'];
		  
		  
		  $res1 = mysqli_query($con,"SELECT * FROM `tbl_master_product` where category_id='$b_id'");
          $brand['categories']=array();
		   while($row1=mysqli_fetch_array($res1))
		   {
			$category['product_id'] = $row1['product_id'];
			$category['product_name'] = $row1['product_name'];
			$category['hsn_code'] = $row1['hsn_code'];
            $brand['categories'][]=$category;		
		   }
		   
		  $response['brands'][]=$brand;	   
	   }

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