What are the differences between using the count function and mysql_result in PHP for counting records?

When counting records in PHP using MySQL, it is recommended to use the count function rather than mysql_result for better performance and accuracy. The count function directly retrieves the count of records from the database, while mysql_result requires an additional query to fetch the count, which can be slower and less efficient.

// Using count function to count records
$query = "SELECT COUNT(*) FROM table_name";
$result = mysqli_query($connection, $query);
$row = mysqli_fetch_array($result);
$count = $row[0];
echo "Total records: " . $count;