Can it be added directly in a mysql query?

1

I would like to know if there is a possibility to update a field in mysql, if you can see what was previously to add the new amount.

I have a field of units that has an XX value and I want to add a new quantity. Normally I make a query first to see that value and then in an update add the old value with the new one.

Can it be simplified?

the code I usually use is this:

 $CExisteArti = Consulta_Dinamica("Simple","*","Stock","'idarticulo' = '".$CExisteEan["idcosa"]."' AND 'almacen' = '".$_POST['AValmacen']."' AND 'idEan' = '".$CExisteEan["id"]."' ");

 $Nstock = $CExisteArti["stock"] + $_POST["AVcantidad"];

 $ModStock = Actualizar_Datos("Stock" , "'stock' = '$Nstock' ","idarticulo","".$CExisteEan["idcosa"].""," AND 'almacen' = '".$_POST['AValmacen']."' ");

It is not that it is vital to do it in a single consultation, it is simply to simplify and add knowledge.

Thousand thanks to everyone.

    
asked by Killpe 21.08.2017 в 19:19
source

1 answer

1

It is possible to add in a UPDATE without the SELECT previous, it would be something like this:

UPDATE Inventario SET Stock = Stock + "Nueva cantidad"
    
answered by 21.08.2017 / 19:27
source