可以在 MySQL 结果中包含 PHP 数据吗?让我解释一下自己:
两张表,一张包含用户的操作,一张包含用户信息。我会查询操作并检索用户 ID 并按用户分组计算每个操作:
$ids = $conn->fetchAll('SELECT origin,COUNT(*) as actions from action WHERE `brand` = ' . $id . ' AND SUBSTRING(origin,1,3)<>"pct" GROUP BY origin');
然后我获取该结果数组并使用它从另一个表中输入用户信息:
$norm_ids = '(';
foreach ($ids as $ids) {
$norm_ids .= $ids['origin'] .',';
}
$norm_ids = substr_replace($norm_ids ,"",-1) .')';
$users = $conn->fetchAll('SELECT * from userinfo WHERE `id` in ' . $norm_ids . ' ORDER BY `name`');
我想$users
包括COUNT(*)
我在上一个查询中得到的,这可以直接在查询中吗?