What are the potential pitfalls of using MySQL for adding values in a column until a certain value is reached?

One potential pitfall of using MySQL for adding values in a column until a certain value is reached is that it may require multiple queries to achieve the desired result, leading to inefficiency and potential performance issues. To solve this, you can use a single SQL query with a combination of UPDATE and CASE statements to increment the column value until the desired value is reached.

<?php
// Connect to MySQL database
$mysqli = new mysqli("localhost", "username", "password", "database");

// Set the desired value to reach
$desired_value = 100;

// Update the column value until the desired value is reached
$query = "UPDATE table_name SET column_name = 
          CASE
            WHEN column_name + 10 <= $desired_value THEN column_name + 10
            ELSE $desired_value
          END";
$mysqli->query($query);

// Close database connection
$mysqli->close();
?>