您好我有一个调用模型方法的控制器,如下所示: 现在,在我的第一个查询中,我想要获取低于100的值,而在另一个查询中,我想获取高于100的值!此外,我想将它们发送到我的控制器中的两个不同的阵列所以请在这里指导我。
$ firstarray包含所有登录数据,但现在我想要另一个数组,其中我的条目低于100。
public function index()
{
$firstarray = $this->data['attendances'] = $this->attendance_m->join_data();
$this->data['attendance_dropdown'] = $this->attendance_m->get_emp_list();
$this->data['subview'] = 'admin/attendance/index';
$this->load->view('admin/_layout_main', $this->data);
}
我的模型包含此方法:
public function join_data()
{
$filter_date = $this->input->post('date_data');
$date = new DateTime($filter_date);
$new_date = $date->format('Y-m-d');
$name = $this->input->post('attendance-list');
$this->db->select('*');
$this->db->from('daily_data2');
$this->db->where('users.emp_id',$name);
$this->db->where('entry >','100');
$this->db->where('date(date_data)',$new_date);
$this->db->order_by("date_data","ASC");
$this->db->join('users', 'users.emp_id = daily_data2.emp_id','inner');
$query = $this->db->get();
$res = $query->result();
echo $this->db->last_query();
return $res;
$this->db->select('*');
$this->db->from('daily_data2');
$this->db->where('users.emp_id',$name);
$this->db->where('entry <=','100');
$this->db->where('date(date_data)',$new_date);
$this->db->order_by("date_data","ASC");
$this->db->join('users', 'users.emp_id = daily_data2.emp_id','inner');
$query2 = $this->db->get();
$rese = $query2->result();
echo $this->db->last_query();
return $rese;
}
答案 0 :(得分:2)
是的,你可以这样做,你需要设置数组前100个条目数据和第二个100条目数据然后你可以返回它。看我的代码:
public function join_data()
{
$filter_date = $this->input->post('date_data');
$date = new DateTime($filter_date);
$new_date = $date->format('Y-m-d');
$name = $this->input->post('attendance-list');
$this->db->select('*');
$this->db->from('daily_data2');
$this->db->where('users.emp_id',$name);
// $this->db->where('entry >','100');
$this->db->where('date(date_data)',$new_date);
$this->db->order_by("date_data","ASC");
$this->db->join('users', 'users.emp_id = daily_data2.emp_id','inner');
$query = $this->db->get('',100,100); //Return data > 100
$res_1 = $query->result();
$this->db->select('*');
$this->db->from('daily_data2');
$this->db->where('users.emp_id',$name);
// $this->db->where('entry <=','100');
$this->db->where('date(date_data)',$new_date);
$this->db->order_by("date_data","ASC");
$this->db->join('users', 'users.emp_id = daily_data2.emp_id','inner');
$query2 = $this->db->get('',100,0); //Return data <= 100
$res_2 = $query2->result();
$returned_data = [
'data_after_100' => $res_1,
'data_below_100' => $res_2
];
return $returned_data;
}