jeudi 9 janvier 2020

if - else in multiple update in one query

I have an issue with this query:

foreach ($_POST['cod'] as $i => $cod) {
    $sth = $conn->prepare("UPDATE LPRODALMACEN SET `existencia` = `existencia` + :comprado WHERE `cod` = :cod");
    $sth->bindParam(':comprado', $tExiste[$i]);
    $sth->bindParam(':cod', $_POST['cod'][$i]);
    $sth->execute();
    $i++;
}

I need make an if - else if the condition is 1 or 0, with this:

$_POST['medida'][$i] == '0' ? $_POST['comprado'][$i] : $_POST['tExiste'][$i];

How can I put inside of the query if the $medida is == 0 add the value from $comprado or if medida is == 1 the value from $tExiste?

Aucun commentaire:

Enregistrer un commentaire