Counting countries

Counting countries

am 20.09.2004 14:33:32 von Bruce Therrien

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 =< 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


--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: Counting countries

am 20.09.2004 14:42:16 von Jochen Wiedmann

Bruce Therrien wrote:
> 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.

Are you sure, that you do not simply need the query

SELECT COUNT(*), country FROM $tablename GROUP BY country

and then read the counts (column 0) and the country names
(column 1)?


Jochen


--
http://lilypie.com/baby1/050423/1/5/1/+1

--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: Counting countries

am 20.09.2004 14:42:16 von Jochen Wiedmann

Bruce Therrien wrote:
> 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.

Are you sure, that you do not simply need the query

SELECT COUNT(*), country FROM $tablename GROUP BY country

and then read the counts (column 0) and the country names
(column 1)?


Jochen


--
http://lilypie.com/baby1/050423/1/5/1/+1

--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org