How to Update a Table Field Without Losing Previous Data in Magento

databasemagento-1

I have a situation in which I need to fill a field of my custom table with new data without losing the existing data. Currently when I submitting data, data exist in this field will get overwritten by new data. Which is the best method to do it?

Below I am providing the necessary details:

  • my custom module model : banner/banner
  • table name : banner
  • field that I need to update : images

Best Answer

Seems like you want to save a part of model. Set value for the column to be updated and save it. Whwn you submitting data try the following.

// Assume the images column's value is $value and the id is $id.
$row = Mage::getModel('banner/banner')->load($id)
$row->setImages($value)->save();

The above code will only update the 'images' field with the given value. It won't affect to the other fields of that row.

Related Topic