Counting instances of a phrase

I have a MySQL database with entries such as

ID Country Colour
1 England Blue
2 France Blue
3 Germany White
4 England White
5 Spain Orange
6 England Red

I want it to count how many times ‘England’ is in that field and display it on the webpage (using PHP). So it would say something like:

England - 3

Thanks for any help.

Well, the simple way would be like this:
SELECT COUNT(*) as total FROM database-name WHERE Country LIKE ‘%England%’

This would return a value of $row[‘total’]. Or the number of records for England.
You could go further and do a group-by to select all countries and their totals and then display each.
But, you requested only England, so there you have it…

1 Like
Sponsor our Newsletter | Privacy Policy | Terms of Service