$sql='select distinct section_id,section_name,count(*) as count from (select* from checkup_form_section where Status="Active"and section_id in ('.$checkup.') ) as c left JOIN checkup_parameter on checkup_parameter.checkup_form_section_id=c.section_id and enabled="Y" group by section_id ';
error_log("sql 1st".$sql);
$result=mysqli_query($conn,$sql);
$sql1='select parameter_value,input_type,section_id,column_order,checkup_parameter_id,parameter_name,column_name from (select checkup_form_section_id,column_order,checkup_parameter_id ,parameter_name,input_type,column_name,parameter_value from checkup_parameter WHERE enabled="Y" and checkup_form_section_id in ('.$checkup.')) as c inner JOIN checkup_form_section on checkup_form_section.section_id=c.checkup_form_section_id and Status="Active" order by checkup_form_section_id,column_order';
$result1=mysqli_query($conn,$sql1);
error_log("heading query ".$sql1);
$sql2="select c.*,p.* from checkup_form c left join patient_master p on c.emp_id = p.id where p.designation_id='".$designation_id."' and c.checkup_type_id='".$checkup_type_id."' and (c.current_status='DRA') $dates";
$data="select distinct cf.checkup_form_key,cf.checkup_form_value,cf.checkup_form_id,c.* ,cp.input_type from checkup_form c left join checkup_form_key_value cf on c.checkup_id=cf.checkup_form_id left join checkup_parameter cp on cp.`column_name`=cf.checkup_form_key where checkup_form_section_id in (".$checkup.") and c.checkup_type_id='".$checkup_type_id."' and emp_id='".$row3['emp_id']."' and c.checkup_id='".$row3['checkup_id']."' and c.checkup_type_id='".$checkup_type_id."' and enabled='Y' $dates order by checkup_form_section_id,column_order";
<td><?=getCommaSeperatedValuesForInClause("select parameter_value_name from checkup_parameter_value",'parameter_value_id',$row_data['checkup_form_value'])?>