Forum Moderators: coopster

Message Too Old, No Replies

creating totals based on field input

         

lubeguy

11:59 pm on Oct 14, 2005 (gmt 0)

10+ Year Member



I am trying to create a report with PHP that pulls data from a mysql database. Lets say in table called survey I have a field called zipcode, in which users fill out a form and enter their zip code. In the database the following entries have been made in the zipcode field:

92602
91730
92620
92315
92314
92314
92314

I want the folowing to appear in the report (zip codes entered and the number of times they have been entered.):

92602 - 2
91730 - 1
92315 - 1
92314 - 3

CAn anyone get me going in the right direction?

jatar_k

2:58 am on Oct 15, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



take a look at this page
[dev.mysql.com...]

it should be fairly straight forward with COUNT and GROUP BY

totally untested

SELECT columnname, COUNT(columnname) FROM tablename GROUP BY columnname

lubeguy

9:27 pm on Oct 18, 2005 (gmt 0)

10+ Year Member



Thanks, that is exactly what I was looking for.