你有一個額外的,
,缺少一個右)
和派生表別名:
<?php include "config.php"; ?>
<?php $results = mysql_query(
"SELECT sum(hit) as total
FROM (
SELECT sum(hit) hit from sound
UNION ALL SELECT sum(hit) hit from soundK
UNION ALL SELECT sum(hit) hit from soundD
) rs") ;
while ($row = mysql_fetch_array($results)) { ?>
<?php echo $row['total'];?>
<?php }?>
如果你想3個人列:
<?php include "config.php"; ?>
<?php $results = mysql_query(
"SELECT soundHits, soundKHits, soundDHits
FROM (
SELECT sum(hit) soundHits from sound
) a, (
SELECT sum(hit) soundKHits from soundK
) b, (
SELECT sum(hit) soundDHits from soundD
) c") ;
while ($row = mysql_fetch_array($results)) { ?>
soundHits: <?php echo $row['soundHits'] ;?>
soundKHits: <?php echo $row['soundKHits'] ;?>
soundDHits: <?php echo $row['soundDHits'] ;?>
<?php }?>
給你的數據庫結構..因爲你需要一個表映射到其他使用聯接..所以你需要外鍵 –
這是在同一個表而不是三個不同的領域,它來自三個不同的表中相同的字段名稱。 – paxdiablo