CodeIgniter Forums
Help! Error saving to DB when different fields share equal data [RESOLVED] - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Help! Error saving to DB when different fields share equal data [RESOLVED] (/showthread.php?tid=8851)



Help! Error saving to DB when different fields share equal data [RESOLVED] - El Forum - 06-03-2008

[eluser]JoostV[/eluser]
Hi,

I use active record for updating data. Works like a breeze, except when two fields in my set() array have the same value. In that case only the first of the two fields is updated. Can anybody help me out here? Am I doing something utterly stupid?

Code example failure
The field 'cat_active' will NOT be updated, because it has the same value as 'cat_catset_id'
Code:
$array = array('cat_catset_id' => '1','cat_title' => 'News','cat_active' => '1');
$this->db->set($array);
Above code will produce this query:
UPDATE `pa_categories` SET `cat_catset_id` = '1', `cat_title` = 'News' WHERE `cat_id` = 1

Code example success
However, if I appoint different data to 'cat_active' and 'cat_catset_id', both fields are updated just fine!
Code:
$array = array('cat_catset_id' => '1','cat_title' => 'News','cat_active' => '0');
$this->db->set($array);
Above code will produce this query:
UPDATE `pa_categories` SET `cat_catset_id` = '1', `cat_title` = 'News', `cat_active` = '0' WHERE `cat_id` = 1

It is driving me crazy! Can anybody explain what is happening here?


Help! Error saving to DB when different fields share equal data [RESOLVED] - El Forum - 06-03-2008

[eluser]Symcrapico[/eluser]
Have you tried using many set()?

Also, have you tried to use 1 instead of '1'?


Help! Error saving to DB when different fields share equal data [RESOLVED] - El Forum - 06-03-2008

[eluser]JoostV[/eluser]
Hi all,

Indeed, I was doing something utterly stupid Sad

I run the query from a model and it starts by running a query to check if this item exists. This query messes op the $this->db->set() I used in the controller, of course.

Sorry to have bothered you with my obliviance.