Jump to content

[SOLVED] count all records in a database


british_government

Recommended Posts

hi, does anyone know a way to count all records in a database?

i have looked around the net and cannot find anything that helps much.

the main problem is that the ammount of tables and table names are constantly changing in the database, the only route i could think of is to find all the tables, count the records in each and add them up, i know phpmyadmin does something like this but im not sure how!

 

any help appreciated

 

Sam

Link to comment
https://forums.phpfreaks.com/topic/55630-solved-count-all-records-in-a-database/
Share on other sites

The only way I can think of doing it is this way:

$sql = "SHOW TABLES" ;

$result = mysql_query($sql,$connection)  or die('Query failed: ' . mysql_error());

$total = 0;
while($table = mysql_fetch_row($result)){
$sql = "SELECT COUNT(*) FROM `" . $table[0] . "`";
$result2 = mysql_query($sql, $connection);
$row = mysql_fetch_row($result2);
$total += $row[0];
}

echo $total;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.