What are the potential pitfalls of using mysql_num_rows() to count total records in a database with a LIMIT clause?

Using mysql_num_rows() to count total records in a database with a LIMIT clause can be inaccurate because it only counts the number of rows returned by the query, not the total number of rows in the database. To accurately count the total number of rows, you can use a separate query to count the total number of rows without the LIMIT clause.

// Query to get total number of rows in the database
$totalRowsQuery = "SELECT COUNT(*) FROM table_name";
$totalRowsResult = mysqli_query($connection, $totalRowsQuery);
$totalRows = mysqli_fetch_array($totalRowsResult)[0];

// Query to get limited number of rows
$query = "SELECT * FROM table_name LIMIT 10";
$result = mysqli_query($connection, $query);

// Count the number of rows returned by the query
$numRows = mysqli_num_rows($result);

echo "Total number of rows in the database: " . $totalRows;
echo "Number of rows returned by the query: " . $numRows;