british_government Posted June 14, 2007 Share Posted June 14, 2007 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 Quote Link to comment Share on other sites More sharing options...
Corona4456 Posted June 14, 2007 Share Posted June 14, 2007 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; Quote Link to comment Share on other sites More sharing options...
british_government Posted June 14, 2007 Author Share Posted June 14, 2007 you are a genius! been trying to work that out for ages! thanks for the help! Sam Quote Link to comment Share on other sites More sharing options...
Corona4456 Posted June 14, 2007 Share Posted June 14, 2007 no problem Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.