What is the purpose of using limitQuery in PHP when fetching data from a database?

When fetching data from a database in PHP, using the limitQuery helps to limit the number of results returned by the query. This can be useful when dealing with large datasets to improve performance and reduce the amount of data transmitted over the network. By using limitQuery, you can specify the maximum number of rows to retrieve from the database, making your queries more efficient.

// Example of using limitQuery to fetch only 10 rows from a database table
$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.";
}