I've been using this block snippet for a while from here
<?php
echo "<h3>Most active in the last week</h3>";
$active_week_result = db_query_range("
SELECT uid, SUM(count) sum FROM
(
(SELECT u.uid, COUNT(DISTINCT(n.nid)) count
FROM {users} u
LEFT JOIN {node} n ON u.uid = n.uid
WHERE u.uid <> 0
AND n.type = 'forum'
AND n.created > %d - (7 * 24 * 60 * 60)
GROUP BY u.uid)
UNION
(SELECT u.uid, COUNT(DISTINCT(c.cid)) count
FROM {users} u
LEFT JOIN {comments} c ON c.uid = u.uid
WHERE u.uid <> 0
AND c.timestamp > %d - (7 * 24 * 60 * 60)
GROUP BY u.uid)
ORDER BY count DESC
)
as x
GROUP BY uid
ORDER BY count DESC
", time(), time(),
0, 10); //Change the second number in this line to the number of results you want to get.
$list = array();
while($row = db_fetch_array($active_week_result)){
$account = user_load(array('uid' => $row['uid']));
$list[] = theme('username', $account) ." (". $row['sum'] .")";
}
print theme('item_list', $list);
?>What it does is count nodes and comments per user, sort highest to lowest and display the top ten... in the last 7 days.
What I want it to do is count all nodes and comments except those associated with taxonomy term with tid of 199 (which happens to be a hidden forum).
I've attempted to do another SELECT within the SELECTs but have very little knowledge of how to write proper SQL, so it didn't work.
Nodes are related to taxonomy terms in "term node" (nid and tid columns).
I guess comments are related to taxonomy terms only distantly by their relationship to nodes.
So how can this query be changed to exclude nodes associated w/tid 199... and then also how to exclude comments associated with those nodes?
Comments
Bump
Any sql gurus that help me out a bit? I've tried some things but no luck yet.
You've either probably
You've either probably figured it out or given up but if you want to exclude something from your query use "<>" for "not equal to". Like for example... WHERE uid <> %d, $account->uid
So the above example would exclude the profile owner from being included if your on the user profile page.
Thanks
I am still working on this actually. Just tabled it for a while.