在一个查询中使用MySQLI计算总用户数和家族数

时间:2014-06-06 08:13:58

标签: php mysql

我希望从我的数据库返回2值,

这是我在2个查询中所做的:

$con = mysqli_connect("127.0.0.1",$user_database,$password_database,$nama_database) or die(" User atau Password Database tidak Valid ");
$select_total_user=mysqli_fetch_array(mysqli_query($con, "SELECT count(`acct_username`) from `pvpgn_BNET`"));
$total_user=$select_total_user[0];
$select_total_clan=mysqli_fetch_array(mysqli_query($con, "SELECT count(`name`) from `pvpgn_clan`"));
$total_clan=$select_total_clan[0];

我想要返回的值是Total Users和Total Clans 在单个查询中 感谢

2 个答案:

答案 0 :(得分:4)

在单个查询中,可以像

一样完成
select
( SELECT count(`acct_username`) from `pvpgn_BNET`) as total_user,
( SELECT count(`name`) from `pvpgn_clan` ) as total_clans ;

您可以按索引名total_usertotal_clans

执行查询和获取数据

答案 1 :(得分:1)

select count(acct_username) AS c1, count(name) AS c2 FROM `pvpgn_BNET`, `pvpgn_clan`;