mardi 7 septembre 2021

php mysql updating a column only where there are duplicates in an if statement

I have this problem i can't seem to solve. I'm kinda new at programming so it could be really easy but i couldn't find anything. I have a big array through which I loop and if there are duplicates they need to be set to false in a column called address_correct. Here is my code:

    $sql1 = "SELECT street, entity_id FROM adresfix";

    $arraycorrect = [];
    $arrayincorrect = [];
    $i = 0;

    $db_query = $db->query($sql1);
    $adres_rows = $db_query->fetch_all();
    var_dump($adres_rows);

    foreach ($address_rows as $address) {
        if (in_array($address_rows[$i][0] , $arraycorrect)){
            echo "Good";
            array_push($arrayincorrect, $address_rows[$i][0]);
            $sql = "UPDATE adresfix SET address_correct = 'false' WHERE";
        } else {
            array_push($arraycorrect, $address_rows[$i][0]);
            echo "False";   
        }
        $i++;
    }

I have no idea what is should put after where in the sql query to make sure only the duplicates are updated. Can anybody help me with this problem?

Aucun commentaire:

Enregistrer un commentaire