1

I have a non Eav Table and I want to update an attribute in a row where param1=a and param2=b. In sql terms : update mytable column=ab where column1=a and column2=b; I have tried this way:

$mymodel=Mage::getModel(test/test)->getCollection()
->addAttributeToFilter('column1',array('eq'=>'a')
->addAttributeToFilter('column2',array('eq'=>'b');
$var=(int)$mymodel->getData('column');
$var=+1;

Uptil here i am able to get my desired column and make change here

$mymodel=setColumn($var)->save();

but by using this i am unable to save the value back in db. Can anyone point me where I am doing wrong?What are the alternative ways to execute this query?

EDIT: Another problem I am facing is in my getData line it's showing me the value 1 instead of value 5 which is stored in my DB.

asked Nov 26, 2015 at 11:55

1 Answer 1

1

Try bellow code

$collection =Mage::getModel('test/test')->getCollection()
 ->addAttributeToFilter('column1',array('eq'=>'a')
 ->addAttributeToFilter('column2',array('eq'=>'b');
foreach($collection as $test) {
 $test->setColumn1('123');
 $test->setcolumn2('345');
 $test->setId($test->getId());
 $test->save();
 //or 
 $test->setData(array('column1' => '123', 'column2' => '345'));
 $test->setId($test->getId());
 $test->save();
}
Marius
199k55 gold badges431 silver badges837 bronze badges
answered Nov 26, 2015 at 12:01
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.