Welcome Guest, Not a member yet? Register   Sign In
Help! Error saving to DB when different fields share equal data [RESOLVED]
#1

[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?
#2

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

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

[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.




Theme © iAndrew 2016 - Forum software by © MyBB