I need to access a table by referencing another table ID and by doing so I created first a foreach loop to retrieve the first table data then give its ID reference to the second table. I have done it in my other function but I don’t know in this function prompts me that it’s undefined index. Here is my model:
function retrieve_Sched($id)
{
$this->db->select('*');
$this->db->from('schedule');
$this->db->where('EmpID',$id);
$query = $this->db->get();
if($query->num_rows() == 0)
{
return false;
}
else
{
return $query->result_array();
}
}
and here is the controller function:
foreach($data['result'] as $val)
{
$data['schedule'] = $this->DBmodel->retrieve_Sched($val['EmpID']);
if($data['schedule'] == false)
{
$consTimeIn = '05:30';
$consLunchOut = '10:50';
$consLunchIn = '13:00';
$consTimeOut = '17:00';
}
else
{
$consTimeIn = $data['schedule']['TimeFrom'];
$consLunchOut = $data['schedule']['LunchOut'];
$consLunchIn = $data['schedule']['LunchIn'];
$consTimeOut = $data['schedule']['TimeTo'];
}
}
This is the error that I get:
ERROR – 2016-05-23 09:57:02 –> Severity: Notice –> Undefined index: TimeFrom C:xampphtdocsTMSapplicationcontrollerstms.php 482
ERROR – 2016-05-23 09:57:02 –> Severity: Notice –> Undefined index: LunchOut C:xampphtdocsTMSapplicationcontrollerstms.php 483
ERROR – 2016-05-23 09:57:02 –> Severity: Notice –> Undefined index: LunchIn C:xampphtdocsTMSapplicationcontrollerstms.php 484
ERROR – 2016-05-23 09:57:02 –> Severity: Notice –> Undefined index: TimeTo C:xampphtdocsTMSapplicationcontrollerstms.php 485
ERROR – 2016-05-23 09:58:41 –> Severity: Notice –> Undefined index: TimeFrom C:xampphtdocsTMSapplicationcontrollerstms.php 482
ERROR – 2016-05-23 09:58:41 –> Severity: Notice –> Undefined index: LunchOut C:xampphtdocsTMSapplicationcontrollerstms.php 483
ERROR – 2016-05-23 09:58:41 –> Severity: Notice –> Undefined index: LunchIn C:xampphtdocsTMSapplicationcontrollerstms.php 484
ERROR – 2016-05-23 09:58:41 –> Severity: Notice –> Undefined index: TimeTo C:xampphtdocsTMSapplicationcontrollerstms.php 485
Advertisement
Answer
This solves my problem:
if($data['result'] == false)
{
echo 'Sorry files have already been processed';
}
else
{
foreach($data['result'] as $val)
{
$data['check'] = $this->DBmodel->check_Sked($val['EmpID']);
if($data['check'] == false)
{
$consTimeIn = "05:30";
$consLunchOut = "10:50";
$consLunchIn = "13:00";
$consTimeOut = "17:00";
}
else
{
$data['schedule'] = $this->DBmodel->retrieve_sched($val['EmpID'],$val['ValidDate']);
if($data['schedule'] == false)
{
$consTimeIn = "05:30";
$consLunchOut = "10:50";
$consLunchIn = "13:00";
$consTimeOut = "17:00";
}
else
{
foreach($data['schedule'] as $value)
{
$conTimeIn = $value['TimeFrom'];
$consTimeOut = $value['TimeTo'];
if($value['LunchOut'] == NULL || $value['LunchOut'] == "")
{
$consLunchOut = @date('H:i',@strtotime($consTimeIn,'+4 hour'));
}
else
{
$consLunchOut = $value['LunchOut'];
}
if($value['LunchIn'] == NULL || $value['LunchIn'] == "")
{
$consLunchIn = @date('H:i',@strtotime($consTimeIn,'+6 hour'));
}
else
{
$consLunchIn = $value['LunchIn'];
}
}
}
}