I have fields in a table that are being constantly updated with the current time (each second). First, the controller calls a function to create the record in the database

public function saveEntry($theuser='')
    {   
        $data = array(
           'theuser' => $theuser ,
           'dateentered' => date('Y-m-d') , //date('d-m-Y H:i:s') ,
           'gname' => date('d-m-Y H:i:s') ,
                   'ldate' => date('Y-m-d'),
                   'ltime' => date('H:i:s'),
                   'ldatetime' => date('Y-m-d H:i:s')
                    );      
        $this->db->insert('onlineusers', $data);        
    }

Then, after the view is called, an ajax function keeps updating the time on the database.
The problem is that when ajax updates the database (with a simple .php update page), the time is less 10 or so minuts than when Codeigniter's function created the record. The difference bettwen CodeIgniter and a simple .php file is, always, more or less 10 minuts
What could I be doing wrong? Is there a way to sincronize the two? Or some other way possible to solve the problem?

My thanks in advanced

Recommended Answers

All 2 Replies

Hi,

It should not depend on CodeIgniter, this can relate to the system in which PHP is executed: in the case is not synchronized. Have you tried to display the date time from a CodeIgniter view? If you can, compare it with a simple script, for example:

echo date('d-m-Y H:i:s');

It could be that some insert queries are failing, in this case it can be helpful to see the ajax call and the Controller.

In the same time when function above is executed, you can execute query on you DB table
SELECT CURTIME()
too and compare those two results.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.