I have this query:
$queryf = "SELECT * FROM classifieds
WHERE city IN ('$cities') AND state IN ('$states')
ORDER BY FIELD (city, '$cities'), datetime DESC";
$cities is an array of nearby cities within 5 miles. Same with states.
Basically, I want to search my user information table that has user-inputted information (like a craigslist/classifieds type table), and COUNT the number of rows PER CITY. So that it’s possible to echo something like:
10 results found within 5 miles:
Dublin, CA (8 records)
Hayward, CA (2 records)
Does anyone know how I’d be able to track/return the amount of rows where the city is identical?
A
GROUP BY, together withCOUNT()should give you what you need: