dongtun1209 2015-02-08 16:36
浏览 281
已采纳

计算多个MySQL表中的行数?

Here's my current code:

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

?>

What I'm trying to do is add up how many rows are in several tables.

The problem I'm having is that every time I refresh the page, the number is either 200 or 216. However, the actual number of rows it should be showing is 14.

I have no idea what could be causing this to happen, I've run each of the queries directly in phpMyAdmin and they show the correct results. Any idea?

EDIT: In case it makes a different, some of the tables are currently empty.

  • 写回答

2条回答 默认 最新

  • duanqiu9104 2015-02-08 16:42
    关注

    If you need an estimate you could try something like this:

    SELECT SUM(TABLE_ROWS) FROM INFORMATION_SCHEMA.TABLES
    WHERE TABLE_NAME LIKE 'apis_hashes_%';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大