Tuesday, February 22, 2022

[FIXED] Completion date status of an event codeigniter

Issue

screenshot of code screenshot of db 2nd screenshot of db I'm currently working on a function that displays the status of an event. I made a column in my db for the event status.

0 - cancelled, 1 - upcoming, 2 - on-going, 3- done.

I want to know how do i change the values of the status in the db by comparing the date of my event to the current date in codeigniter. Is it possible? if yes, how? If not, are there any ways to do the function?

snippet of my db


Solution

You should get current date using PHP syntax not now() and also need to update only single record. Check below code:

        $resulting = $query->result_array(); 
        $currentDateTime = date('Y-m-d H:i:s');
        foreach($resulting as $resultings){ 
            $date = $resultings['eventDate']; 
            $this->db->where('activityId', $resultings['activityId']);
            if (strtotime($currentDateTime) == strtotime($date)) { 
                 $this->db->update('activity', array('eventStatus' => 1));
            } else if (strtotime($currentDateTime) < strtotime($date)) { 
                 $this->db->update('activity', array('eventStatus' => 3));
            } else if (strtotime($currentDateTime) > strtotime($date)) { 
                 $this->db->update('activity', array('eventStatus' => 1));
            } 
        }

Hope it helps you.



Answered By - Rohit Mittal

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.