mardi 2 février 2021

How to do an if-else condition in sql and php?

What I want to do is a select query and then if it is true set a variable of a table called 'afiliadospadron' to 1 but if it is false (it do not return anything) just set the variable to 0. My code isn't working. Can somebody help me please?

$query= "select nrodoc from oct20 where nrodoc = 05463xx union select nrodoc from dic20 where nrodoc = 054631xx";
$query2= "update afiliadospadron set condVotar = '1' where nroDoc = '5463xxx' ";
//$query3= "UPDATE afiliadospadron SET condVotar = 0 WHERE nroDoc = '5463xxx'";
if ($query) {
    $query2;
    } else {
        echo "next time";
//    $query3 = "UPDATE afiliadospadron SET condVotar = 0 WHERE nroDoc = '5463192'";;
    }
$statement = $conexion->prepare($query);
$statement = $conexion->prepare($query2);
//$statement = $conexion->prepare($query3);
$statement->execute();

Aucun commentaire:

Enregistrer un commentaire