I am trying 2 modify the forums module to change the way forum pages display their topics, specifically I want to extend the information they show about a topic on this page.
To this end I tried to extend this query from forum_get_topics so as to also include the comments table (from whence I could fetch the replies subject, name & timestamp)
$sql = db_rewrite_sql("SELECT n.nid, f.tid, n.title, n.sticky, u.name, u.uid, n.created AS timestamp, n.comment AS comment_mode, l.last_comment_timestamp, IF(l.last_comment_uid != 0, cu.name, l.last_comment_name) AS last_comment_name, l.last_comment_uid, l.comment_count AS num_comments FROM {node_comment_statistics} l, {users} cu, {term_node} r, {users} u, {forum} f, {node} n WHERE n.status = 1 AND l.last_comment_uid = cu.uid AND n.nid = l.nid AND n.nid = r.nid AND r.tid = %d AND n.uid = u.uid AND n.vid = f.vid");
The catch is I'm rubbish at SQL and only slowly getting to grips with the functions in the forums module. The first step I tried was adding {comments} c to the FROM statement, so as to be able to select columns from it but this immediately broke the forums page.
Each topic was listed 7 times on the page, much to my befuddlement.
Any ideas why adding a table to FROM should do this?
Looking at it, and the theming functions that further process the results, this approach is looking less and less viable anyway so that's not really important, I'm just curious!