I want to count the amount of times that a zip code is entered into a database. I'm not sure if I am using the right function or not. Also eventually I need to separate the zip codes by the year they were entered int the data base. I know how to separate the years-I think. What I really need help on is counting duplicate entries Here is my code.
$sql = 'SELECT * FROM zip ORDER BY time_register';
$result = mysql_query($sql,$db) or die(mysql_error(). "
SQL: $sql");
$row = mysql_fetch_array($result);
do{
$visitor_zip= array();
$register = $row['time_register'];
$register_year = date(Y,$register);
print_r(array_count_values($visitor_zip));
}while($row = mysql_fetch_array($result))
-----------------------------------------------------------------------------------
HERE IS MY FINAL CODE THAT WORKS!!!!!!!!
$sql = "SELECT visitor_zip
AS zip
, COUNT(visitor_zip
) AS cnt
FROM zip
GROUP BY visitor_zip
ORDER BY visitor_zip";
$result = mysql_query($sql,$db) or die(mysql_error(). "
SQL: $sql");
print '<table class="zip"><tr><td><b>Zip</b></td><td># of</td></tr>';
while($row = mysql_fetch_array($result))
{
print '<tr><td>' . $row['zip'] .'</td><td>'. $row['cnt'] . '</td></tr>';
}
print '</table>';