What is the correct syntax for using the IN keyword in a MySQL query in PHP?

When using the IN keyword in a MySQL query in PHP, you need to make sure to properly format the values that you want to check against. The values should be enclosed in parentheses and separated by commas. This allows you to check if a particular column value is present in a list of specified values.

// Example of using the IN keyword in a MySQL query in PHP
$ids = [1, 2, 3]; // Array of values to check against
$idsString = implode(',', $ids); // Convert array to a comma-separated string

$sql = "SELECT * FROM table_name WHERE id IN ($idsString)";
$result = $conn->query($sql);

// Loop through the results
if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        // Process the data
    }
} else {
    echo "No results found.";
}