我需要将count(activity\ type)group by user\ posted\ to保存到mysql查询的一个变量中
$query = "
SELECT user_posted_to, COUNT(*)
FROM activity_log_table
WHERE
post_type = 'discussion'
AND activity_type = 'Like' ";
$query .= "AND activity_timestamp >= CURRENT_DATE - INTERVAL 7 DAY AND activity_type <= CURRENT_DATE ";
$query .= "GROUP BY user_posted_to ORDER BY activity_timestamp DESC LIMIT 25";
$result = mysqli_query($connection, $query);
while ($row = mysqli_fetch_assoc($result)) {
$user_posted_to = (int)$row['user_posted_to'];
$timestamp = time();
// I need to insert the count into this table for number_assert
$query2 = "INSERT INTO top_weekly (user_id, number_assert, timestamp) VALUES ($user_posted_to, $timestamp)";
$result2 = mysqli_query($connection, $query2);
$confirm_query2 = confirm_query($result2);
if($confirm_query2) {
echo "success query 2";
} else {
echo "failed query 2";
}
}
我希望将count()group by保存到一个php变量中,以便以后在页面上使用它
2条答案
按热度按时间km0tfn4u1#
将和作为标签添加到count(*)之后,您将能够读出您得到的行中的标签。
fzsnzjdm2#
你想给« 计数(*) » 去别的地方,比如« 碳纳米管 ». 然后,您可以在获取后按名称访问该列,如下所示: