$query_search_enroll = "SELECT subject.sub_name, teacher.tea_name, term.term_no, enroll.regis_date, department.dep_name, subject.code_sub, enroll.student_id, class.cla_name, personal.name, personal.ID,teacher.id
FROM term INNER JOIN (teacher INNER JOIN ((department INNER JOIN subject ON department.ID = subject.dep_id) INNER JOIN ((class INNER JOIN personal ON class.ID = personal.class_id) INNER JOIN enroll ON personal.ID = enroll.student_id) ON subject.ID = enroll.sub_id) ON teacher.ID = subject.tea_id) ON term.ID = enroll.term_id";
if(!empty($_POST['sub_id'])) $query_search_enroll.= " AND sub_id LIKE '%".$_POST['sub_id']."%'";
if(!empty($_POST['class_id'])) $query_search_enroll.= " AND class_id LIKE '%".$_POST['class_id']."%'";
if(!empty($_POST['dep_id'])) $query_search_enroll.= " AND dep_id LIKE '".$_POST['dep_id']."'";
if(!empty($_POST['regis_date'])) $query_search_enroll.= " AND regis_date LIKE '%".$_POST['regis_date']."%'";
if(!empty($_POST['tea_id'])) $query_search_enroll.= " AND tea_id LIKE '%".$_POST['tea_id']."%'";
if(!empty($_POST['term_id'])) $query_search_enroll.= " AND term_id LIKE '%".$_POST['term_id']."%'";