How can the LIMIT clause be correctly added to a SQL query in PHP?

To add the LIMIT clause to a SQL query in PHP, you can simply append "LIMIT x" to the end of your query, where x is the number of rows you want to retrieve. This is useful when you want to limit the number of results returned by a query, especially when dealing with large datasets.

$query = "SELECT * FROM table_name LIMIT 10";
$result = mysqli_query($connection, $query);

if (mysqli_num_rows($result) > 0) {
    while ($row = mysqli_fetch_assoc($result)) {
        // Process each row here
    }
} else {
    echo "No results found.";
}