Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can i increment a field? PHP

How can i increment my qty every time i process i want it to increment the value not just update it?

$prodid = $this->input->post('product')[$x];
  if($prodid){
    $product_quanti = array(
        'qty' => $this->input->post('qty')[$x],
    );
        $this->db->where('id', $prodid);
        $update = $this->db->update('products', $product_quanti);

    }

i tried this

 $prodid = $this->input->post('product')[$x];
  if($prodid){
    $product_quanti = array(
        'qty' => $this->input->post('qty')[$x] + $this->input->post('qty')[$x],
    );
        $this->db->where('id', $prodid);
        $update = $this->db->update('products', $product_quanti);

    }

but every time i process it it just randomly increment a number i the qty was 200 and when i input 500 it randomly return 1000 how can i increment it in the correct way?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

how can i make the avaiable stock + incoming stock formula?

>Solution :

You are setting the value to twice the input, instead of the current value + the input. So 500 will result in 1000.

You can do something like this instead:

$inputQuantity = (int)$this->input->post('qty')[$x];
$this->db->where('id', $prodid);
$this->db->set('qty', "qty+$inputQuantity", false);
$this->db->update('products');
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading