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.

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();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.