Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you count the number of records in a database?

Status
Not open for further replies.

meeble

Programmer
Sep 24, 2002
137
GB
How do you count the number of records in a database?

If you have:

$db = mysql_connect("localhost","foot","blah");

mysql_select_db("foot",$db);

$result = mysql_query("SELECT * FROM cat",$db);

I tried using count myrow but this doesn't work.


Cheers

James
 
You could try

Code:
SELECT COUNT(*) AS the_count FROM cat

or

Code:
SHOW TABLE STATUS LIKE 'cat'


Each query will return a set of columns. In the first, the only column returned, "the_count", will contain the row count.

In the second, the column "Rows" will contain the number of rows in the table.

For more information on SHOW TABLE STATUS: Want the best answers? Ask the best questions: TANSTAAFL!
 
or the more traditional method

1, 2, 3, 4, 5...etc

you get the point [rofl2] [soapbox]
sleep is good
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top