$query ="SELECT distinct pno_unit_code,unit_hindi,def_type FROM `sub_unitmaster` WHERE def_type=1 union all SELECT distinct sub_unit_code,sub_unit_hindi,def_type FROM `sub_unitmaster` WHERE def_type=2" ;
$empquery=mysql_query($query) or die("Error in query = ".mysql_error());
$i=1;
while($row=mysql_fetch_array($empquery)){
if($row['def_type']==1){
//$transrs=mysql_query("Selcet count(*) as transfer from new_posting_detail where joining_unit=".$row['pno_unit_code']." and transfer_posting_flag='A'");
$joinrs=mysql_query("SELECT count(*) as joinings from new_posting_detail where joining_unit=".$row['pno_unit_code']." and transfer_posting_flag='TP'") or die(mysql_error());
$relivingrs=mysql_query("SELECT count(*) as reliving from new_posting_detail where joining_unit=".$row['pno_unit_code']." and transfer_posting_flag='T'");
$transfers=mysql_query("SELECT count(*) as transfer from new_posting_detail where joining_unit=".$row['pno_unit_code']." and transfer_posting_flag='A'");
}else if($row['def_type']==2){
//$transrs=mysql_query("Selcet count(*) as transfer from new_posting_detail where joining_sub_unit=".$row['pno_unit_code']." and transfer_posting_flag='A'");
$joinrs=mysql_query("SELECT count(*) as joinings from new_posting_detail where joining_sub_unit=".$row['pno_unit_code']." and transfer_posting_flag='TP'") or die(mysql_error());
$relivingrs=mysql_query("SELECT count(*) as reliving from new_posting_detail where joining_sub_unit=".$row['pno_unit_code']." and transfer_posting_flag='T'");
$transfers=mysql_query("SELECT count(*) as transfer from new_posting_detail where joining_sub_unit=".$row['pno_unit_code']." and transfer_posting_flag='A'");
}
// $transfercnt=mysql_fetch_assoc($transrs);
$joiningcnt=mysql_fetch_assoc($joinrs);
$relivingcnt=mysql_fetch_assoc($relivingrs);
$transfercnt=mysql_fetch_assoc($transfers);
?>