Show List of Cities and How many records are in that city.

I have a database full of cities. The table name is “needs” What I’m looking for is a php script that looks through all the cities (“city” is the name of the column in the database) and if there is a city then it will post on the page the city name and how many records are in that city.

Example is if there are 10 records in Jonesboro and 3 in Harrisburg then the page will look like this:

Jonesboro (10)
Harrisburg (3)

Any help?

Look at this example for a start, your going to have to use the WHERE option in your SQL statement to limit the rows to the city names.

http://php.net/manual/en/function.mysql-num-rows.php

Give the code a shot and if you cannot get it to work post it here and I will help you.

Sponsor our Newsletter | Privacy Policy | Terms of Service