How can the LIMIT clause be effectively used in PHP to limit the number of results returned from a query?

To limit the number of results returned from a query in PHP, you can use the LIMIT clause in your SQL query. This clause allows you to specify the maximum number of rows to return from the query result set. By using the LIMIT clause, you can control the amount of data retrieved from the database, which can help improve performance and reduce memory usage.

// Example SQL query with LIMIT clause to retrieve only 10 rows
$sql = "SELECT * FROM table_name LIMIT 10";
$result = mysqli_query($connection, $sql);

// Loop through the results
while($row = mysqli_fetch_assoc($result)) {
    // Process each row here
}