By Fixdit on
What would this static db query look like as a dynamic one?
It counts the number of forum posts by users and ranks them in order of the most active.
$resource = db_query("
SELECT users.uid AS uid, COUNT(node_users.nid) AS node_users_nid
FROM {users} users
LEFT JOIN {node} node_users ON users.uid = node_users.uid
WHERE (( (users.status <> '0') AND (node_users.type IN ('forum')) ))
GROUP BY uid
ORDER BY COUNT(node_users.nid) DESC
LIMIT 3 OFFSET 0
");
Also, what's the best practice for iterating over and rendering out the results of this as a list.
This didn't seem to work?
foreach ($resource as $record) {
$items[] = $record;
}
$block['content'] = theme('item_list', $items);
All input welcome.
Many thanks in advance,
Peter
Comments
Dynamic in what way? For the
Dynamic in what way?
For the second part, $record is an object so you need to do something with $record.uid and/or $record.node_users_nid.
In the form of a Dynamic
In the form of a Dynamic query: http://drupal.org/node/310075
Nobody?
Does anyone know what I need to have the static query above use dynamic query syntax instead?