Counting countries

Bruce Therrien <[email protected]>
Newsgroups gmane.comp.db.mysql.perl
Message-ID <[email protected]>
Trying to count the number of countries in a MySQL database. 
Each client has a country entered, and we want to add the total
countries we are in and display on our site.
The following code is not working correctly. 
Any help appreciated.....

$SQL =<<SQL;
select count(distinct(country)), country as total3 from $tablename
SQL
$sth = $dbh->prepare($SQL);
if(!$sth) { die("Error: " . $dbh->errstr . "\n"); }
if(!$sth->execute) { die("Error: " . $sth->errstr . "\n"); }

$match = 0;
if($sth->rows != 0)
{
$total_rows = $sth->rows;
$match = 1;

for ($counter = 0; $counter < $total_rows; $counter++)
{
my($ref) = $sth->fetchrow_hashref;

$totalcountries = $ref->{'total3'};

open(NUM,">$data_directory/country_count.txt");
flock (NUM, 2);
print NUM "$totalcountries";
close(NUM);
}
}
$sth->finish();






This is the end of the internet. 
Please turn around and go back.
-- 
Bruce Therrien <[email protected]>


-- 
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe:    http://lists.mysql.com/[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.