=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 . ")"; } $i = 0; $record = array(); if (isset($year) && $year != '' && sizeof($year1) > 1) { $param_query = "select param_id, param_name from history_parameter $qry_filter1"; $result_param = mysqli_query($conn, $param_query); $query = "SELECT count(*) as total FROM patient_master where status='Active' $qry_filter "; if (!$result = @mysqli_query($conn, $query)) { exit(mysqli_error($conn)); } if (mysqli_num_rows($result) > 0) { if ($row = mysqli_fetch_assoc($result)) { $total_count = $row['total']; } } $total = 0; while ($param_row = mysqli_fetch_assoc($result_param)) { $param_id = $param_row['param_id']; for ($j = 0; $j < sizeof($year1); $j++) { $percentage_emp_per_illness = 0; $total = 0; $qry_date = ""; $qry_date .= " and year(checkup_date) ='" . $year1[$j] . "'"; $count_illness = "select max(checkup_id) from checkup_form where emp_id in (SELECT id FROM `patient_master` where status='Active' $qry_filter ORDER by id asc) $qry_date1 $qry_date and past_present_illness like '%$param_id, %' or '%$param_id$' GROUP BY emp_id ORDER BY emp_id asc"; $illness_result = mysqli_query($conn, $count_illness); if (mysqli_num_rows($illness_result) > 0) { $total = mysqli_num_rows($illness_result); } else { $total = 0; } error_log("query:" . $count_illness); error_log("ftotal:" . $total . "Year:" . $year1[$j] . "param_id:" . $param_id); $percentage_emp_per_illness = ($total / $total_count) * 100; $record[$param_row['param_name']][$year1[$j]]['illness'] = round($percentage_emp_per_illness, 2); } } } else { if (isset($year2) && $year2 != '') { $qry_date .= " and year(checkup_date) ='" . $year2 . "'"; } $param_query = "select param_id,param_name from history_parameter $qry_filter1"; $result_param = mysqli_query($conn, $param_query); $total_hbd_pat = 0; while ($param_row = mysqli_fetch_assoc($result_param)) { $param_id = $param_row['param_id']; $param_name = $param_row['param_name']; $count_illness = "select max(checkup_id) from checkup_form where emp_id in (SELECT id FROM `patient_master` where status='Active' $qry_filter ORDER by id asc) and past_present_illness like '%$param_id,%' or '%$param_id$' $qry_date1 $qry_date GROUP BY emp_id ORDER BY emp_id asc"; $illness_result = mysqli_query($conn, $count_illness); error_log("count_illness::" . $count_illness); if (mysqli_num_rows($illness_result) > 0) { $total_hbd_pat = mysqli_num_rows($illness_result); } else { $total_hbd_pat = 0; } $record[$i]['key'] = $param_name; $record[$i]['total'] = $total_hbd_pat; $query = "SELECT count(*) as total FROM patient_master where status='Active' $qry_filter "; if (!$result = @mysqli_query($conn, $query)) { exit(mysqli_error($conn)); } if (mysqli_num_rows($result) > 0) { if ($row = mysqli_fetch_assoc($result)) { $record[$i]['total_count'] = $row['total']; } } $i++; } } echo json_encode($record);