Home » Php » php – set entire column to zero and then update a specific row

php – set entire column to zero and then update a specific row

Posted by: admin February 25, 2020 Leave a comment

Questions:

I want firstly antire def column set to be 0 except the row where id is a variable (this should be 1).

$sql = "update rolls set def = 0, def = 1 where id = :aid";
$st = $db->prepare($sql);
$st->execute([":aid" => $id]);

result – the first part – set to 0 – doesn’t work;

Any help?

How to&Answers:

Separate into 2 queries

// Query one ; query two
$sql = "update rolls set def = 0; update rolls set def = 1 where id = :aid";
$st = $db->prepare($sql);
$st->execute([":aid" => $id]);