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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.