Home > Mobile >  How can i increment a field? PHP
How can i increment a field? PHP

Time:12-03

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?

how can i make the avaiable stock incoming stock formula?

CodePudding user response:

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');
  • Related