这是我目前的代码:
<?php
$identifiers_link = mysql_connect("localhost", "XXXXX", "XXXXX");
mysql_select_db("XXXXX", $identifiers_link);
$count_0 = mysql_query("SELECT COUNT(hash_id) FROM apis_hashes_0", $identifiers_link);
$count_1 = mysql_query("SELECT COUNT(hash_id) FROM apis_hashes_1", $identifiers_link);
$count_2 = mysql_query("SELECT COUNT(hash_id) FROM apis_hashes_2", $identifiers_link);
$count_3 = mysql_query("SELECT COUNT(hash_id) FROM apis_hashes_3", $identifiers_link);
$count_4 = mysql_query("SELECT COUNT(hash_id) FROM apis_hashes_4", $identifiers_link);
$count_5 = mysql_query("SELECT COUNT(hash_id) FROM apis_hashes_5", $identifiers_link);
$count_6 = mysql_query("SELECT COUNT(hash_id) FROM apis_hashes_6", $identifiers_link);
$count_7 = mysql_query("SELECT COUNT(hash_id) FROM apis_hashes_7", $identifiers_link);
$count_8 = mysql_query("SELECT COUNT(hash_id) FROM apis_hashes_8", $identifiers_link);
$count_9 = mysql_query("SELECT COUNT(hash_id) FROM apis_hashes_9", $identifiers_link);
$count_a = mysql_query("SELECT COUNT(hash_id) FROM apis_hashes_a", $identifiers_link);
$count_b = mysql_query("SELECT COUNT(hash_id) FROM apis_hashes_b", $identifiers_link);
$count_c = mysql_query("SELECT COUNT(hash_id) FROM apis_hashes_c", $identifiers_link);
$count_d = mysql_query("SELECT COUNT(hash_id) FROM apis_hashes_d", $identifiers_link);
$count_e = mysql_query("SELECT COUNT(hash_id) FROM apis_hashes_e", $identifiers_link);
$count_f = mysql_query("SELECT COUNT(hash_id) FROM apis_hashes_f", $identifiers_link);
$identifiers_count = $count_0 + $count_1 + $count_2 + $count_3 + $count_4 + $count_5 + $count_6 + $count_7 + $count_8 + $count_9 + $count_a + $count_b + $count_c + $count_d + $count_e + $count_f;
echo $identifiers_count;
?>
我想要做的是添加多个表中的行数。
我遇到的问题是,每次刷新页面时,数字都是200或216.但是,它应显示的实际行数是14。
我不知道是什么导致这种情况发生,我直接在phpMyAdmin中运行每个查询并显示正确的结果。有什么想法吗?
编辑:如果它有所不同,有些表目前是空的。
答案 0 :(得分:0)
如果您需要估算,可以尝试这样的事情:
SELECT SUM(TABLE_ROWS) FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME LIKE 'apis_hashes_%';
答案 1 :(得分:0)
您正在使用count
,因此您必须运行循环。您的每个查询都应如下所示
$query_0 = mysql_query("SELECT COUNT(hash_id) as count FROM apis_hashes_0", $identifiers_link);
while($row=mysql_fetch_array($query_0)){
$count_0 = $row['count'];
}
希望这有助于你