How to count MySQL array values? For example, the below code
$get = mysqli_query("SELECT * FROM clicks WHERE uid='$id'");
while($comp = mysqli_fetch_array($db, $get)) {
$country = $comp['country'];
echo "$country<br>";
}
will give output country names in the table country as
India
India
Pakistan
India
United States
Japan
United States
United States
India
I want to count the number of times each country appears in the table and store the values as:
['Country', 'Counts'],
['India', 4],
['Pakistan', 1],
['United States', 3],
['Japan', 1],
group byclausegroup by, a fundamental part of SQL. You should learn the basics of SQL if you want to use databases at all effectively.