What are the best practices for comparing numerical values, such as points, in a MySQL query to achieve the desired result in PHP?

When comparing numerical values, such as points, in a MySQL query to achieve the desired result in PHP, it is important to use the appropriate comparison operators (e.g., >, <, =) and ensure that the data types match. Additionally, it is recommended to sanitize user input to prevent SQL injection attacks.

// Example of comparing numerical values in a MySQL query in PHP
$points = 50;

// Sanitize user input
$points = intval($points);

// Query to fetch rows with points greater than the specified value
$query = &quot;SELECT * FROM table_name WHERE points &gt; $points&quot;;

// Execute the query and fetch results
$result = mysqli_query($connection, $query);

// Process the results
if (mysqli_num_rows($result) &gt; 0) {
    while ($row = mysqli_fetch_assoc($result)) {
        // Output or process the fetched data
    }
} else {
    echo &quot;No results found.&quot;;
}