if ($i == count($data)-1) {
$id = $data[0]['id'];
$query = "UPDATE colors SET state = 1 WHERE id = $id";
$result = mysqli_query($link, $query);
} else {
$id = $data[$i++]['id'];
echo $i;
$query = "UPDATE colors SET state = 1 WHERE id = $id";
$result = mysqli_query($link, $query);
}