⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

DateTime + Time in CallbackAfterInsert



msquare
  • profile picture
  • Member

Posted 10 March 2013 - 13:46 PM

I have a callback function which needs to add the recently entered datetime, and time from a different table. However, it updates the db with null. I tried re-updating it with the initial datetime input and it works fine. I'm guessing the problem is along the addition part. HELP!

 

Here's the callback...

function add_path_after_insert($post_array,$primary_key)
{
    $this->load->model('admin_model');
    $pdep=$this->admin_model->get_pathDep($primary_key);
    $sdep=$this->admin_model->get_schedDep($primary_key);

    $currentDate = strtotime($pdep);
    $futureDate = $currentDate+(((int)substr($sdep,0,2))*3600)+(((int)substr($sdep,3,2)) * 60) + ((int) substr($sdep,6,2));
    $data = array(
        'dep_datetime' => $futureDate
    );
		
    $this->db->where('path_id', $primary_key);
    $this->db->update('path', $data); 

    return true;
}

 

From the model...

function get_schedDep($path_id)
{
    $query=$this->db->query('SELECT dep_time FROM schedule JOIN path ON schedule.sched_id= path.sched_id WHERE path_id="'.$path_id.'"');
    $row=$query->row(); 
    return $row->dep_time; 
}

function get_pathDep($path_id)
{
    $query=$this->db->query('SELECT dep_datetime FROM path WHERE path_id="'.$path_id.'"');
    $row=$query->row(); 
		
    return $row->dep_datetime;
}

davidoster
  • profile picture
  • Member

Posted 10 March 2013 - 18:42 PM

Hello and welcome.

Show the controller function that has the add_path_after_insert.