我试图从具有多个查询的数据库中获取表格格式的数据。我得到的确切数据,但数据得到的数据是相同的数据,反复超过千次。我需要一个帮助来解决这个问题,以获得实际数据而不是下面的多个数据是我的代码。请看一下。我没有收到任何错误,但我得到的数据是多次重复数据。
controller:
public function getReports()
{
$records = [];
$data = [];
$data['title'] = 'test Report';
$date_type = $this->input->get('filter_options');
$course = $this->input->get('course');
$filter_options = $date_type;
$department = $this->input->get('department');
$division = $this->input->get('division');
$month = 1;
$year = date('Y');
$day = date('d');
$data['department'] = $department;
$data['course'] = $course;
$data['division'] = $division;
$data['date_type'] = $date_type;
$course_condition = ' AND 1=1 ';
if($course)
$course_condition = ' AND o.title="'.$course.'"';
$department_condition = ' AND 1=1 ';
if($department)
$department_condition = ' AND u.department="'.$department.'"';
$date_condition = ' and 1=1 ';
if($date_type==1)
{
$date_condition = ' and ta.submittimestamp BETWEEN DATE_SUB(NOW(), INTERVAL 300 DAY) AND NOW() ';
//dd($date_condition);
}
else if($date_type==2)
{
$date_condition = ' and MONTH(ta.submittimestamp) = MONTH(CURRENT_DATE())
AND YEAR(ta.submittimestamp) = YEAR(CURRENT_DATE()) ';
}
else if($date_type==3)
{
$year = $this->input->get('year');
$month = $this->input->get('month');
$date_condition = ' and YEAR(ta.submittimestamp) = "'.$year.'" and MONTH(ta.submittimestamp) = "'.$month.'" ';
}
$group_condition = "GROUP by u.usr_id";
if ($course)
$users_query="SELECT o.title as course_title,u.*,u.usr_id,o.obj_id FROM object_data o,usr_data u,obj_members rn WHERE o.obj_id=rn.obj_id AND u.usr_id=rn.usr_id AND o.type='crs' AND o.obj_id=$course";
$user_records = $this->base_model->executeSelectQuery($users_query);
$final_data = [];
foreach($user_records as $user)
{
if(!$course)
continue;
$user_course_query="SELECT *, (select obj_id FROM object_reference f WHERE e.child = f.ref_id limit 1 ) as final_reference FROM object_data a , object_data g,tree c,tree e , object_reference b ,object_reference f,object_reference d WHERE a.obj_id = b.obj_id AND b.ref_id = c.parent AND c.child = d.ref_id AND d.ref_id = e.parent AND f.obj_id = g.obj_id AND a.obj_id=$course ";
$user_course_records = $this->base_model->executeSelectQuery($user_course_query);
foreach($user_course_records as $course_data)
{
$final_reference=$course_data->final_reference;
$user_tests_query = "SELECT u.firstname,o.*,ta.*,tpr.workingtime,tcr.mark_official,(tcr.reached_points/tcr.max_points)*100 as result FROM usr_data u,object_data o,tst_active ta,tst_tests tt ,tst_pass_result tpr, tst_result_cache tcr WHERE u.usr_id=ta.user_fi AND tt.obj_fi=o.obj_id AND ta.test_fi=tt.test_id AND ta.active_id=tpr.active_fi AND tcr.active_fi=ta.active_id AND u.usr_id=$user->usr_id AND o.obj_id = $final_reference ".$date_condition;
$user_tests = $this->base_model->executeSelectQuery($user_tests_query);
foreach($user_tests as $test)
{
$dta['usr_id'] = $user->usr_id;
$dta['firstname'] = $user->firstname;
$dta['email'] = $user->email;
$dta['matriculation'] = $user->matriculation;
$dta['approve_date'] = $user->approve_date;
$dta['department'] = $user->department;
$dta['tries'] = $test->tries;
$dta['test_title'] = $test->title;
$dta['submittimestamp'] = $test->submittimestamp;
$dta['workingtime'] = $test->workingtime;
// $dta['mark_official'] = $test->mark_official;
$dta['result'] = $test->result;
if($test->mark_official=='passed')
$result_status = '<span class="label label-primary"> Passed </span>';
else if($test->mark_official=='failed')
$result_status = '<span class="label label-danger"> Failed </span>';
$dta['status'] = $result_status;
$dta['division'] = $this->udfTextData(2);
$dta['job_title'] = $this->udfTextData(6);
$final_data[] = $dta;
}
}
}
$data['records'] = $final_data;