List:General Discussion« Previous MessageNext Message »
From:Nigel Parker Date:July 1 1999 7:47am
Subject:RE: COUNT()
View as plain text  
DBI has a row function which returns number of rows selected (use it after the query is
executed):

$total_number_of matches = $sth->rows;

Or something similar.  Check your DBI docs or the MySQL reference manual for the exact
details...

Nigel Parker

-----Original Message-----
From:	toxalot@stripped [SMTP:toxalot@stripped]
Sent:	Wednesday, June 30, 1999 5:26 PM
To:	mysql@stripped
Subject:	COUNT()

I am trying to figure out how to use the COUNT() function. I am using perl
and DBI

I want to find out how many records are returned by this statement

SELECT main.pro_id,main.pro_name,main.city,main.province,main.type FROM
main,specials WHERE main.pro_id IN ($PRO_IDS) AND specials.pro_id IN
($SPEC_PRO_IDS) AND main.pro_id=specials.pro_id GROUP BY pro_name

If I add a COUNT(*) into the first part of the SELECT and bind it to a
variable like I did the others, I get a count of 3 when there are about
1000 records returned.

Here is an excerpt of my code. I would like to print out the total number
of records at the top before I print the list of them.

$sql="SELECT main.pro_id,main.pro_name,main.city,main.province,main.type
FROM main,specials WHERE main.pro_id IN ($PRO_IDS) AND specials.pro_id IN
($SPEC_PRO_IDS) AND main.pro_id=specials.pro_id GROUP BY pro_name";
$sth = $dbh->prepare($sql);
$sth->execute();
$sth->bind_columns( undef, \$pro_id,\$pro_name,\$city,\$province,\$type);
while( $sth->fetch() ) {
      &province;
      &owner_type;
      print "<INPUT TYPE=\"CHECKBOX\" NAME=\"company\" VALUE=\"$pro_id\">
$pro_name, $city, $province_name, $type_name<br>\n";
}
$sth->finish();

Could someone help me with this and the proper syntax please.

Thank you.


---------------------------------------------------------------------
Please check "http://www.mysql.com/Manual_chapter/manual_toc.html" before
posting. To request this thread, e-mail mysql-thread6282@stripped

To unsubscribe, send a message to the address shown in the
List-Unsubscribe header of this message. If you cannot see it,
e-mail mysql-unsubscribe@stripped instead.

Thread
COUNT()toxalot30 Jun
RE: COUNT()Nigel Parker1 Jul