0

In my database table I have a quantity field.I am trying to add new quantities which will add with previous.

I have tried by this code in controller

$this->request->data['StoreProduct']['quantity']=100+$this->request->data['StoreProduct']['quantity'];

Here this code working fine.But in 100 here I want to place my old data.So at first here I have to sent data which already in database.How can I send this data for add with new data ?

I have sent old data by using find methods, here is the code.

$options = array('conditions' => array('StoreProduct.' . $this->StoreProduct->primaryKey => $id));
        $request= $this->StoreProduct->find('all', $options);

I have succeed to see the quantity in edit.ctp. Now I can I send this edit.ctp to edit method in controller ?

cms
  • 106
  • 8
  • Duplicate of hundreds of questios like that: http://stackoverflow.com/questions/8773457/cakephp-increment-value – mark Nov 11 '14 at 11:23

1 Answers1

0

First, get the data using

$data = $this->StoreProduct->find('first',array('conditions'=>array('StoreProduct.id'=>$id)));

then add the data

$this->request->data['StoreProduct']['quantity']=$data['StoreProduct']['quantity']+$this->request->data['StoreProduct']['quantity'];