PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, February 22, 2022

[FIXED] Completion date status of an event codeigniter

 February 22, 2022     codeigniter, php, phpmyadmin     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

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

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing