deviloper
deviloper

Reputation: 7240

I cant run an update query in codeigniter

function updateVisitsStatus($today){
        /*
         * 
        $this->db->select('exp_datetime, status_id');
        $this->db->from('visits');
        $this->db->where('exp_datetime <', $today);
        $this->db->where('status_id', 0);
        echo "<pre>"; print_r($this->db->get()->result());exit;
         * 
         */

        $this->db->where('exp_datetime <', $today);
        $this->db->where('status_id', 0);
        $this->db->update('visits', 'status_id = -4 ');
    }

The commented query prints two records with the given conditions. So The query is supposed to update two records with the new value in the field status_id but it actually does not.

What am I missing in this process?

Upvotes: 2

Views: 48

Answers (2)

Dexter
Dexter

Reputation: 1796

try like this

$data = array(
          'status_id' => -4
         );
$this->db->where(" exp_datetime < '".$today."'");
$this->db->where('status_id', 0);
$this->db->update('visits',$data);

Upvotes: 1

Jenz
Jenz

Reputation: 8369

You have to pass the values as an array or an object to the function update. Try with,

// define array of values
$data = array(
               'status_id' => -4
            );
$this->db->where('exp_datetime <', $today);
$this->db->where('status_id', 0);
$this->db->update('visits',$data);

Upvotes: 2

Related Questions