Welcome Guest, Not a member yet? Register   Sign In
[solved] SET and UPDATE
#1

[eluser]SPeed_FANat1c[/eluser]
My code:
Code:
function addClick()
    {
        $this->db->set('clicks','clicks+1');
        $this->db->where('filename',$this->input->post('filename'))->update('jos_reklama_banners');
        echo $this->db->last_query();
    }

I see that it generates such query

Code:
UPDATE `jos_reklama_banners` SET `clicks` = 'clicks+1' WHERE `filename` = 'file26.jpg'

But this query does not increase the value of clicks. The query that works should be

Code:
UPDATE `jos_reklama_banners` SET clicks = clicks+1 WHERE `filename` = 'file26.jpg'

you can see that the word clicks is without ' signs. That causes the problem. How to make what I want using active record? Or do I have to use $this->db->query('my statement') ?
#2

[eluser]danmontgomery[/eluser]
This specific case is covered in the user guide.

http://ellislab.com/codeigniter/user-gui...tml#update

Quote:set() will also accept an optional third parameter ($escape), that will prevent data from being escaped if set to FALSE. To illustrate the difference, here is set() used both with and without the escape parameter.

Code:
$this->db->set('field', 'field+1', FALSE);
$this->db->insert('mytable');
// gives INSERT INTO mytable (field) VALUES (field+1)

$this->db->set('field', 'field+1');
$this->db->insert('mytable');
// gives INSERT INTO mytable (field) VALUES ('field+1')
#3

[eluser]SPeed_FANat1c[/eluser]
oh, thanks, I saw it but didn't pay attention, just skipped because I thought why I would ever need to set escape to FALSE Smile




Theme © iAndrew 2016 - Forum software by © MyBB