=str_to_date('" . $start_date . "','%d-%m-%Y') "; } if (isset($end_date) && $end_date != '') { $qry_date1 .= " and date(checkup_date) <=str_to_date('" . $end_date . "','%d-%m-%Y') "; } if (isset($month) && $month != '') { $qry_date1 .= " and month(checkup_date) in (" . $month . ")"; } $data = array(); if (isset($year) && $year != '' && sizeof($year1) > 1) { for ($j = 0; $j < sizeof($year1); $j++) { error_log("year:" . $year1[$j] . " size:" . sizeof($year1)); $qry_date = ""; $qry_dob = ""; $qry_date .= "and year(checkup_date) ='" . $year1[$j] . "'"; $qry_dob .= "and year(doj) <= '" . $year1[$j] . "'"; $per_for_18_to_25 = []; $total = 0; $pat_query = "SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=18 and YEAR(CURDATE())-year(dob)<25 and status='Active' $qry_filter $qry_dob"; $pat_result = mysqli_query($conn, $pat_query); $total = mysqli_num_rows($pat_result); $count_health_index = "SELECT max(checkup_id),emp_id,health_index from checkup_form where emp_id in (SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=18 and YEAR(CURDATE())-year(dob)<25 and status='Active' $qry_filter $qry_dob) $qry_date1 $qry_date GROUP by emp_id"; error_log("count health_index:" . $count_health_index); $health_index_result = mysqli_query($conn, $count_health_index); $i = 0; if (mysqli_num_rows($health_index_result)) { while ($row_health_index = mysqli_fetch_assoc($health_index_result)) { $per_for_18_to_25[$i] = $row_health_index['health_index']; $i++; } } $avg = 0; if (count($per_for_18_to_25)) { $avg = round(array_sum($per_for_18_to_25) / count($per_for_18_to_25), 2); } $data['18-25'][$year1[$j]]['total'] = $avg; error_log("Query1::" . $count_health_index); $per_for_26_to_30 = []; $total = 0; $pat_query = "SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=25 and YEAR(CURDATE())-year(dob)<30 and status='Active' $qry_filter $qry_dob"; $pat_result = mysqli_query($conn, $pat_query); $total = mysqli_num_rows($pat_result); $count_health_index = "SELECT max(checkup_id),emp_id,health_index from checkup_form where emp_id in (SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=25 and YEAR(CURDATE())-year(dob)<30 and status='Active' $qry_filter $qry_dob) $qry_date1 $qry_date GROUP by emp_id"; error_log("count health_index:" . $count_health_index); $health_index_result = mysqli_query($conn, $count_health_index); $i = 0; if (mysqli_num_rows($health_index_result)) { while ($row_health_index = mysqli_fetch_assoc($health_index_result)) { $per_for_26_to_30[$i] = $row_health_index['health_index']; $i++; } } $avg = 0; if (count($per_for_26_to_30)) { $avg = round(array_sum($per_for_26_to_30) / count($per_for_26_to_30), 2); } $data['25-30'][$year1[$j]]['total'] = $avg; error_log("Query2::" . $count_health_index); $per_for_31_to_40 = []; $total = 0; $pat_query = "SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=30 and YEAR(CURDATE())-year(dob)<40 and status='Active' $qry_filter $qry_dob"; $pat_result = mysqli_query($conn, $pat_query); $total = mysqli_num_rows($pat_result); $count_health_index = "SELECT max(checkup_id),emp_id,health_index from checkup_form where emp_id in (SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=30 and YEAR(CURDATE())-year(dob)<40 and status='Active' $qry_filter $qry_dob) $qry_date1 $qry_date GROUP by emp_id"; error_log("count health_index:" . $count_health_index); $health_index_result = mysqli_query($conn, $count_health_index); $i = 0; if (mysqli_num_rows($health_index_result)) { while ($row_health_index = mysqli_fetch_assoc($health_index_result)) { $per_for_31_to_40[$i] = $row_health_index['health_index']; $i++; } } $avg = 0; if (count($per_for_31_to_40)) { $avg = round(array_sum($per_for_31_to_40) / count($per_for_31_to_40), 2); } $data['30-40'][$year1[$j]]['total'] = $avg; error_log("Query3::" . $count_health_index); $per_for_41_to_50 = []; $total = 0; $pat_query = "SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=40 and YEAR(CURDATE())-year(dob)<50 and status='Active' $qry_filter $qry_dob"; $pat_result = mysqli_query($conn, $pat_query); $total = mysqli_num_rows($pat_result); $count_health_index = "SELECT max(checkup_id),emp_id,health_index from checkup_form where emp_id in (SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=40 and YEAR(CURDATE())-year(dob)<50 and status='Active' $qry_filter $qry_dob) $qry_date1 $qry_date GROUP by emp_id"; error_log("count health_index:" . $count_health_index); $health_index_result = mysqli_query($conn, $count_health_index); $i = 0; if (mysqli_num_rows($health_index_result)) { while ($row_health_index = mysqli_fetch_assoc($health_index_result)) { $per_for_41_to_50[$i] = $row_health_index['health_index']; $i++; } } $avg = 0; if (count($per_for_41_to_50)) { $avg = round(array_sum($per_for_41_to_50) / count($per_for_41_to_50), 2); } $data['40-50'][$year1[$j]]['total'] = $avg; error_log("Query4::" . $count_health_index); $per_greater_than_50 = []; $total = 0; $pat_query = "SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=50 and status='Active' $qry_filter $qry_dob"; $pat_result = mysqli_query($conn, $pat_query); $total = mysqli_num_rows($pat_result); $count_health_index = "SELECT max(checkup_id),emp_id,health_index from checkup_form where emp_id in (SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=50 and status='Active' $qry_filter $qry_dob) $qry_date1 $qry_date GROUP by emp_id"; error_log("count health_index:" . $count_health_index); $health_index_result = mysqli_query($conn, $count_health_index); $i = 0; if (mysqli_num_rows($health_index_result)) { while ($row_health_index = mysqli_fetch_assoc($health_index_result)) { $per_greater_than_50[$i] = $row_health_index['health_index']; $i++; } } $avg = 0; if (count($per_greater_than_50)) { $avg = round(array_sum($per_greater_than_50) / count($per_greater_than_50), 2); } $data['>=50'][$year1[$j]]['total'] = $avg; error_log("Query5::" . $count_health_index); } } else { if (isset($year2) && $year2 != '') { $qry_date1 .= " and year(checkup_date) ='" . $year2 . "'"; $qry_dob .= "and year(doj) <= '" . $year2 . "'"; } //for 18 to 25 $total = 0; $pat_query = "SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=18 and YEAR(CURDATE())-year(dob)<25 and status='Active' $qry_filter $qry_dob"; $pat_result = mysqli_query($conn, $pat_query); if (mysqli_num_rows($pat_result)) { $total = mysqli_num_rows($pat_result); } else { $total = 0; } $per_for_18_to_25 = []; $count_health_index = "SELECT max(checkup_id),health_index from checkup_form where emp_id in (SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=18 and YEAR(CURDATE())-year(dob)<25 and status='Active' $qry_filter $qry_dob) $qry_date1 GROUP by emp_id"; error_log("count health_index:" . $count_health_index); $health_index_result = mysqli_query($conn, $count_health_index); $i = 0; if (mysqli_num_rows($health_index_result)) { while ($row_health_index = mysqli_fetch_assoc($health_index_result)) { $per_for_18_to_25[$i] = $row_health_index['health_index']; $i++; } } $avg = 0; if (count($per_for_18_to_25)) { $avg = round(array_sum($per_for_18_to_25) / count($per_for_18_to_25), 2); } $data['age_18_25']['avg'] = $avg; $data['age_18_25']['gtotal'] = $total; //for 26 to 30 $total = 0; $pat_query = "SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=25 and YEAR(CURDATE())-year(dob)<30 and status='Active' $qry_filter"; $pat_result = mysqli_query($conn, $pat_query); if (mysqli_num_rows($pat_result)) { $total = mysqli_num_rows($pat_result); } else { $total = 0; } $per_for_25_to_30 = []; $count_health_index = "SELECT max(checkup_id),health_index from checkup_form where emp_id in (SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=25 and YEAR(CURDATE())-year(dob)<30 and status='Active' $qry_filter $qry_dob) $qry_date1 GROUP by emp_id"; error_log("count health_index:" . $count_health_index); $health_index_result = mysqli_query($conn, $count_health_index); $i = 0; if (mysqli_num_rows($health_index_result)) { while ($row_health_index = mysqli_fetch_assoc($health_index_result)) { $per_for_25_to_30[$i] = $row_health_index['health_index']; $i++; } } $avg = 0; if (count($per_for_25_to_30)) { $avg = round(array_sum($per_for_25_to_30) / count($per_for_25_to_30), 2); } $data['age_25_30']['avg'] = $avg; $data['age_25_30']['gtotal'] = $total; //for 31 to 40 $total = 0; $pat_query = "SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=30 and YEAR(CURDATE())-year(dob)<40 and status='Active' $qry_filter"; $pat_result = mysqli_query($conn, $pat_query); if (mysqli_num_rows($pat_result)) { $total = mysqli_num_rows($pat_result); } else { $total = 0; } $per_for_30_to_40 = []; $count_health_index = "SELECT max(checkup_id),health_index from checkup_form where emp_id in (SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=30 and YEAR(CURDATE())-year(dob)<40 and status='Active' $qry_filter $qry_dob) $qry_date1 GROUP by emp_id"; error_log("count health_index:" . $count_health_index); $health_index_result = mysqli_query($conn, $count_health_index); $i = 0; if (mysqli_num_rows($health_index_result)) { while ($row_health_index = mysqli_fetch_assoc($health_index_result)) { $per_for_30_to_40[$i] = $row_health_index['health_index']; $i++; } } $avg = 0; if (count($per_for_30_to_40)) { $avg = round(array_sum($per_for_30_to_40) / count($per_for_30_to_40), 2); } $data['age_30_40']['avg'] = $avg; $data['age_30_40']['gtotal'] = $total; //for 41 to 50 $total = 0; $pat_query = "SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=40 and YEAR(CURDATE())-year(dob)<50 and status='Active' $qry_filter"; $pat_result = mysqli_query($conn, $pat_query); if (mysqli_num_rows($pat_result)) { $total = mysqli_num_rows($pat_result); } else { $total = 0; } $per_for_40_to_50 = []; $count_health_index = "SELECT max(checkup_id),health_index from checkup_form where emp_id in (SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=40 and YEAR(CURDATE())-year(dob)<50 and status='Active' $qry_filter $qry_dob) $qry_date1 GROUP by emp_id"; error_log("count health_index:" . $count_health_index); $health_index_result = mysqli_query($conn, $count_health_index); $i = 0; if (mysqli_num_rows($health_index_result)) { while ($row_health_index = mysqli_fetch_assoc($health_index_result)) { $per_for_40_to_50[$i] = $row_health_index['health_index']; $i++; } } $avg = 0; if (count($per_for_40_to_50)) { $avg = round(array_sum($per_for_40_to_50) / count($per_for_40_to_50), 2); } $data['age_40_50']['avg'] = $avg; $data['age_40_50']['gtotal'] = $total; //for >50 $total = 0; $pat_query = "SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=50 and status='Active' $qry_filter"; $pat_result = mysqli_query($conn, $pat_query); if (mysqli_num_rows($pat_result)) { $total = mysqli_num_rows($pat_result); } else { $total = 0; } $per_greater_than_equal_50 = []; $count_health_index = "SELECT max(checkup_id),health_index from checkup_form where emp_id in (SELECT id FROM patient_master where YEAR(CURDATE())-year(dob)>=50 and status='Active' $qry_filter $qry_dob) $qry_date1 GROUP by emp_id"; error_log("count health_index:" . $count_health_index); $health_index_result = mysqli_query($conn, $count_health_index); $i = 0; if (mysqli_num_rows($health_index_result)) { while ($row_health_index = mysqli_fetch_assoc($health_index_result)) { $per_greater_than_equal_50[$i] = $row_health_index['health_index']; $i++; } } $avg = 0; if (count($per_greater_than_equal_50)) { $avg = round(array_sum($per_greater_than_equal_50) / count($per_greater_than_equal_50), 2); } while ($row_health_index = mysqli_fetch_assoc($health_index_result)) { $per_greater_than_equal_50[$i] = $row_health_index['health_index']; $i++; } $data['age_more_equal_50']['avg'] = $avg; $data['age_more_equal_50']['gtotal'] = $total; } echo json_encode($data);