Here's the code I've started with:
$result = mysql_query("SELECT * FROM apis_hashes_a", $link);
$count = mysql_num_rows($result);
What I need to do is to get the total sum of all rows for all tables that start with apis_hashes_
.
There are tons of tables and new ones are being added all the time, but all of these tables start with apis_hashes_
at the beginning. Is this something that would be possible to do or do I have to list every table individually in the PHP code?
JUST use SUM()
IN SQL.Use the code below
<?php
$query = "SELECT SUM(TABLE_ROWS) as score
FROM INFORMATION_SCHEMA.TABLES
WHERE SCHEMA = '{your_db_name}'";
$result = mysql_query($query, $link);
while($row=mysql_fetch_array($result)){
$total_rows = $row['score'];
}
echo $total_rows;
?>
Hope this helps you
The sql:
show tables like 'apis_hashes_%'
will return the list of all your tables, then you need loop thru all the names of the tables with the mysql sum()
function.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.