CodeIgniter Forums
What is problem behide my code? - Printable Version

+- CodeIgniter Forums (
+-- Forum: CodeIgniter Archived (from EllisLab) (
+--- Forum: Archived Development & Programming (
+--- Thread: What is problem behide my code? (/thread-25984.html)

What is problem behide my code? - El Forum - 01-03-2010

I test again many time. But i don't know why below code execute wrong result.

This is code for controller
// Update number viewed of topic
            $query = $this->media_topic_model->read($id);
            $result = $query->result();
            if ($result) {
                $item = $this->objectToArray($result[0]);

                $item['topic_viewed'] = intval($item['topic_viewed']) + 1; // Count and inc correctly.
                $this->media_topic_model->update($item['topic_id'], $item);

This code for model
function update($id, $data)
        var_dump($item); // check again data
        $this->db->where('topic_id', $data['topic_id']);
        $this->db->set('user_id', $data['user_id']);
        $this->db->set('topic_parent_id', $data['topic_parent_id']);
        $this->db->set('topic_title_ascii', $data['topic_title_ascii']);
        $this->db->set('topic_name', $data['topic_name']);
        $this->db->set('topic_order', $data['topic_order']);
        $this->db->set('topic_viewed', $data['topic_viewed']);

        return $this->db->affected_rows();

I check var_dump before call $this->media_topic_model->update($item['topic_id'], $item); function and inside this function => data are OK. But when codeigniter core execute. Value of topic_viewed inc 4,5 or 6, 7... . Eg, 10 => 17 ?

Do you meet this problem ?