0

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
5
  • You have to increase the size of the field?
    – Keyul Shah
    Jan 10, 2014 at 2:45
  • nope. but in future i need to do it also. how can we achieve this? Jan 10, 2014 at 2:49
  • In magento if you want to change the table fileld then you have to write update script in magento.
    – Keyul Shah
    Jan 10, 2014 at 3:00
  • okei. can you show me a small demo code for this? Jan 10, 2014 at 3:27
  • Give me some time I will prepare for you and explain you.
    – Keyul Shah
    Jan 10, 2014 at 3:38

2 Answers 2

1

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.

0

I have used following code and it worked for me. This code will collect the data from database and store it into a variable.

 <?php
     $data = $bannerModel -> getCollection() -> getData();
     $bannerNames=$data[0]['images'];
     /*
          followed by code that collect new data from the form field. 
          Then it will store new data to $bannerNames. 
     /*

Your Answer

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

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