Friday, September 22, 2017

How to maintain a history or step by step process in PHP application

Step1:
          $initial_histroy = array(
                            array(
                                'id' => $user_id,
                                'date' => date('Y-m-d H:i: A'),
                                'action' => 'Assigned to ' . strtoupper(username),
                                'remarks' => 'Any remarks or comments.'
                            )
                        );

                        $lead_history = serialize($initial_histroy);

$insertData = array('user_id'=>'1','lead_history '=>$lead_history);
************************************************************************
Step2:
          $lead_history = $this->getLeadHistory($id);
public function getLeadHistory($id){
  $this->db->select('lead_history');
$this->db->where('id', $id);
$query = $this->db->get('tableName');
$data = $query->result_array();
if($data[0]['lead_history']){
$data = $data[0]['lead_history'];
return unserialize($data);
}else
return $data = array();
}


$lead_history[] = array(
'id' => $user_id,
'date'=> date('d-m-Y  h:i A') ,
'action' => "<< ".strtoupper('krishnaraj')." >> Updated << Customer Not Interested Details >> ",'remarks' => 'Reason ');
$updateData = array('last_modified_on'=> date("Y-m-d H:i:s"),'lead_history'=>serialize($lead_history));



How to do required date format from mysql default date format (2017-09-22 into 22-09-2017)



Example:
               1). $this->db->select("date_format(substr(l.last_modified_on,1,10),'%d/%m/%Y') AS last_modified_on");
                    Output: 2017-09-22 12:12:12 into 22/09/2017

               2). SELECT DATE_FORMAT("2017-06-15", "%Y");
                 Output: 2017

                3). SELECT DATE_FORMAT("2017-06-15", "%W %M %e %Y");
                Output: Thursday June 15 2017