• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is problem behide my code?

#1
[eluser]Unknown[/eluser]
I test again many time. But i don't know why below code execute wrong result.

This is code for controller
Code:
// 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.
                var_dump($item);
                $this->media_topic_model->update($item['topic_id'], $item);
            }

This code for model
Code:
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']);
        $this->db->update('media_topic');

        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 ?


Messages In This Thread
What is problem behide my code? - by El Forum - 01-03-2010, 02:50 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.