如何組合來自UNION查詢中使用的所有表的計數。這就是我所擁有的:在UNION查詢中組合條目計數
$query = "SELECT COUNT(*) as num
from table_one LEFT JOIN table_constant on table_one.c_id
= table_constant.c_id
where table_constant.user_id = '$uid'
UNION
SELECT COUNT(*) as num
from table_two LEFT JOIN table_constant on table_two.c_id
= table_constant.c_id
where table_two.added_by = '$uid'
UNION
SELECT COUNT(*) as num
from table_three LEFT JOIN table_constant ON table_three.c_id
= table_constant.c_id
where table_constant.user_id = '$uid'
UNION
SELECT COUNT(*) as num
from table_four LEFT JOIN table_constant ON table_four.c_id
= table_constant.c_id
where table_constant.user_id = '$uid'
ORDER BY date_time_added DESC";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages[num];
嘿。我需要在上面貼出的$ total_pages變量內的計數。我不知道該怎麼做。 – KPO
我已經更新了我的答案,請檢查一下。如果您在查詢中符合工會規則,請執行此操作。從(你的查詢)中選擇count(*)作爲mycount。它爲我工作希望現在你將擺脫你的問題.. – Syeda
一件事Syeda。我如何把它放入一個變量? – KPO