$a = mysql_query("SELECT COUNT(*) as `count_1` FROM `table_1` WHERE `this_1` = '1'");
$b = mysql_fetch_assoc($a);
$c = mysql_query("SELECT COUNT(*) as `count_2` FROM `table_1` WHERE `this_2` = '1'");
$d = mysql_fetch_assoc($c);
最佳答案
使用 UNION ALL 使其成为单个查询:
SELECT COUNT(*) as count_1 FROM table_1 WHERE this_1 = '1' UNION ALL SELECT COUNT(*) as count_2 FROM table_1 WHERE this_2 = '1'
So that would result in
$a = mysql_query("...the complete query from above...");
关于php - 如何将这两个查询合并为一个?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5010745/