这里我正在做一个出勤模块,这意味着所有人都缺席,我将 id 存储在数据库中作为json字符串,这里实际上id <1>在 2017-04-11上不存在和 2017-04-12
id 2缺席 2017-04-11 和 2017-04-13 ,到目前为止工作正常,此后我想做的意思是,我有一个动态变量如 loginId = 2 ,我想显示像id 2这样的结果,这是他缺席的日期,请参阅下面我的预期结果。
student_absent_list(表名)
absendId studentAbsentId studentAbsentDate schoolId
1 ["1","2"] 2017-04-11 2
2 ["1"] 2017-04-12 2
3 ["2"] 2017-04-13 2
我的控制器
public function getAbsentListStaff()
{
date_default_timezone_set('Asia/Kolkata');
$loginType = $_POST['loginType'];
if($loginType == 1)
{
$data = array(
"schoolId" => $_POST['schoolName'],
"classId" => $_POST['className'],
"sectionId" => $_POST['sectionName'],
"loginId" =>$_POST['loginId'],
);
$absentresponse= $this->Android_login_model->admin_options_listdisplayparent($data);
foreach ($absentresponse as $key => $value)
{
$absentresponse[$key]->studentAbsentId= json_decode($value->studentAbsentId,true);
}
if($absentresponse){
$return=array('status'=>"Success",'data'=>$absentresponse);
echo json_encode($return);
}
else{
$return=array('status'=>"Error",'description'=>"Data Not Found");
echo json_encode($return);
}
}
}
我的模特
public function admin_options_listdisplayparent($params)
{
$this->db->select('*');
$this->db->where('status !=', '1');
$this->db->where('schoolId =',$params['schoolId']);
$this->db->where('classId =',$params['classId']);
$this->db->where('sectionId =',$params['sectionId']);
//$this->db->where('studentAbsentDate =',$params['absentDate']);
return $this->db->get('student_absent_list')->result();
}
我的预期结果
{
"status": "Success",
"data": [
{
"studentAbsentId": "2"
"studentAbsentDate": "2017-04-11",
"schoolId": "2",
"response":"absent"
},
{
"studentAbsentId": "2"
"studentAbsentDate": "2017-04-13",
"schoolId": "2",
"response":"absent"
}
]
}
更新回答
{
"status": "Success",
"data": [
{
"absendId": "1",
"studentAbsentId": [
"1",
"2"
],
"studentAbsentDate": "2017-04-11",
"schoolId": "2",
"classId": "1",
"sectionId": "1",
"reg_date": "2017-04-13 01:01:03",
"created_by": "kanniyappan@g2evolution.co.in",
"status": "0"
},
{
"absendId": "2",
"studentAbsentId": [
"1"
],
"studentAbsentDate": "2017-04-12",
"schoolId": "2",
"classId": "1",
"sectionId": "1",
"reg_date": "2017-04-13 01:01:14",
"created_by": "kanniyappan@g2evolution.co.in",
"status": "0"
}
]
}
答案 0 :(得分:0)
尝试重写您的模型,如下所示:
public function admin_options_listdisplayparent($params)
{
$condition = array(
'status !=' => '1',
'schoolId' => $params['schoolId'],
'classId' => $params['classId'],
'sectionId' => $params['sectionId']
);
$this->db->select('*');
$this->db->where($condition);
$this->db->like('studentAbsentId', '"' . $params['loginId'] . '"', 'both');
return $this->db->get('student_absent_list')->result();
}
重写控制器如下:
public function getAbsentListStaff() {
date_default_timezone_set('Asia/Kolkata');
$loginType = $_POST['loginType'];
if($loginType == 1)
{
$data = array(
"schoolId" => $_POST['schoolName'],
"classId" => $_POST['className'],
"sectionId" => $_POST['sectionName'],
"loginId" =>$_POST['loginId'],
);
$absentresponse_data= $this->Android_login_model->admin_options_listdisplayparent($data);
$absentresponse = array();
foreach ($absentresponse_data as $res)
{
$row = array();
$row['studentAbsentId'] = $_POST['loginId'];
$row['studentAbsentDate'] = $res->studentAbsentDate;
$row['schoolId'] = $res->schoolId;
$row['response'] = 'absent';
$absentresponse[] = $row;
}
if(count($absentresponse) > 0){
$return = array('status'=>"Success",'data'=>$absentresponse);
echo json_encode($return);
} else {
$return = array('status'=>"Error",'description'=>"Data Not Found");
echo json_encode($return);
}
}
}