='".$start_date."' "; $qry_date.=" and medical_entry_date >=str_to_date('".$start_date."','%d-%m-%Y') "; } if(isset($end_date) && $end_date!=''){ //$qry_date.=" and checkup_date <='".$end_date."' "; $qry_date.=" and medical_entry_date <=str_to_date('".$end_date."','%d-%m-%Y') "; } $i=0; $record =array(); if($qry_bu!='') $qry_bu=preg_replace('/and/', 'where', $qry_bu, 1); $query1="select id FROM patient_master $qry_bu "; //echo $query1; $query="SELECT count(DISTINCT(patient_id)) as total from medical_examination where bmi<18.5 and patient_id in ($query1) $qry_date"; //echo $query; if (!$result = @mysqli_query($conn,$query)) { exit(mysqli_error($conn)); } if(mysqli_num_rows($result) > 0) { if ($row = mysqli_fetch_assoc($result)) { $record[$i]['key'] ='<18.5'; $record[$i]['total'] =$row['total']; } } $query="SELECT count(patient_id) as total,GROUP_CONCAT(DISTINCT past_present_illness SEPARATOR ',') as illness from medical_examination where bmi<18.5 and patient_id in ($query1) $qry_date group by patient_id Having Find_In_Set(2,illness)>0"; // echo $query; if (!$result = @mysqli_query($conn,$query)) { exit(mysqli_error($conn)); } if(mysqli_num_rows($result) > 0) { if ($row = mysqli_fetch_assoc($result)) { $record[$i]['is_diabetes'] =$row['total']; $i++; } } $query="SELECT count(DISTINCT(patient_id)) as total from medical_examination where bmi>=18.5 and bmi<25 and patient_id in ($query1) $qry_date"; // echo $query; if (!$result = @mysqli_query($conn,$query)) { exit(mysqli_error($conn)); } if(mysqli_num_rows($result) > 0) { if ($row = mysqli_fetch_assoc($result)) { $record[$i]['key'] ='18.5-25'; $record[$i]['total'] =$row['total']; } } $query="SELECT count(patient_id) as total,GROUP_CONCAT(DISTINCT past_present_illness SEPARATOR ',') as illness from medical_examination where bmi>=18.5 and bmi<25 and patient_id in ($query1) $qry_date group by patient_id Having Find_In_Set(2,illness)>0"; if (!$result = @mysqli_query($conn,$query)) { exit(mysqli_error($conn)); } if(mysqli_num_rows($result) > 0) { if ($row = mysqli_fetch_assoc($result)) { $record[$i]['is_diabetes'] =$row['total']; $i++; } } $query="SELECT count(DISTINCT(patient_id)) as total from medical_examination where bmi>=25 and bmi<=30 and patient_id in ($query1) $qry_date"; // echo $query; if (!$result = @mysqli_query($conn,$query)) { exit(mysqli_error($conn)); } if(mysqli_num_rows($result) > 0) { if ($row = mysqli_fetch_assoc($result)) { $record[$i]['key'] ='25-30'; $record[$i]['total'] =$row['total']; } } $query="SELECT count(patient_id) as total,GROUP_CONCAT(DISTINCT past_present_illness SEPARATOR ',') as illness from medical_examination where bmi>=25 and bmi<=30 and patient_id in ($query1) $qry_date group by patient_id Having Find_In_Set(2,illness)>0"; if (!$result = @mysqli_query($conn,$query)) { exit(mysqli_error($conn)); } if(mysqli_num_rows($result) > 0) { if ($row = mysqli_fetch_assoc($result)) { $record[$i]['is_diabetes'] =$row['total']; $i++; } } $query="SELECT count(DISTINCT(patient_id)) as total from medical_examination where bmi>30 and patient_id in ($query1) $qry_date"; if (!$result = @mysqli_query($conn,$query)) { exit(mysqli_error($conn)); } if(mysqli_num_rows($result) > 0) { if ($row = mysqli_fetch_assoc($result)) { $record[$i]['key'] ='>30'; $record[$i]['total'] =$row['total']; } } $query="SELECT count(patient_id) as total,GROUP_CONCAT(DISTINCT past_present_illness SEPARATOR ',') as illness from medical_examination where bmi>30 and patient_id in ($query1) $qry_date group by patient_id Having Find_In_Set(2,illness)>0"; if (!$result = @mysqli_query($conn,$query)) { exit(mysqli_error($conn)); } if(mysqli_num_rows($result) > 0) { if ($row = mysqli_fetch_assoc($result)) { $record[$i]['is_diabetes'] =$row['total']; $i++; } }else{ $record[$i]['is_diabetes'] =0; $i++; } echo json_encode($record); ?>