hey guys,
I’m trying to fit the follwing SQL Query in ->updateByPk()
UPDATE `tb_image` SET `views` = `views` + '1' WHERE `idImage` = 1;
For some reason I can’t get it to work with updateByPk()…
Can anybody help?
hey guys,
I’m trying to fit the follwing SQL Query in ->updateByPk()
UPDATE `tb_image` SET `views` = `views` + '1' WHERE `idImage` = 1;
For some reason I can’t get it to work with updateByPk()…
Can anybody help?
Maybe you could use the updateCounters() method of your AR class:
http://www.yiiframework.com/doc/api/1.1/CActiveRecord/#updateCounters-detail
In your case something like this:
Image::model()->updateCounters(array('views'=>+1), 'idImage=1');
What does “can’t get it work” mean?
Can you show the code you’ve tried?
Ok Thx guys.
updateCounters() what exactly what I was looking for…
Thanks . AR updateCounters() is really good for frequently update count.