Working with a CMS (EE)
I have a query which I'm using to
1) pull in entry info
2) order entries by activity
where activity is defined as the greater of the two values entry_date or recent_comment_date.
Below is the query and it works as advertised
I'd like to update this so if a comment is made to an entry within the selected category, I can display some additional info related to the comment. This data will be coming from the exp_comments table:Code:SELECT DISTINCT m.username, m.avatar_filename, t.title, t.url_title, t.view_count_four, t.comment_total, t.entry_date, t.recent_comment_date, IF(t.entry_date > t.recent_comment_date, t.entry_date, t.recent_comment_date) as recent_activity, cats.cat_url_title FROM exp_members AS m LEFT JOIN exp_weblog_titles AS t ON m.member_id = t.author_id LEFT JOIN exp_category_posts AS cp ON t.entry_id = cp.entry_id LEFT JOIN exp_categories AS cats ON cp.cat_id = cats.cat_id WHERE cats.cat_url_title = 'trends' //where trends is equal to {segment_4} ORDER BY recent_activity DESC
1) {commnet_id}
2) {name} // username of comment author
But when I add this table to the query everything goes haywire.
The above attempt seems to be returning all comments to each entry within the selected category. Not what I want.Code:SELECT DISTINCT c.comment_id, c.name, m.username, m.avatar_filename, t.title, t.url_title, t.view_count_four, t.comment_total, t.entry_date, t.recent_comment_date, IF(t.entry_date > t.recent_comment_date, t.entry_date, t.recent_comment_date) as recent_activity, cats.cat_url_title FROM exp_members AS m LEFT JOIN exp_weblog_titles AS t ON m.member_id = t.author_id LEFT JOIN exp_comments AS c //exp_comments added here on common column of entry_id ON t.entry_id = c.entry_id LEFT JOIN exp_category_posts AS cp ON c.entry_id = cp.entry_id LEFT JOIN exp_categories AS cats ON cp.cat_id = cats.cat_id WHERE t.weblog_id = 6 AND cats.cat_url_title = 'trends' ORDER BY recent_activity DESC
I want to do what my initial query is doing, return each entry within a selected category, and if that entry has a comment, pull in the data for {comment_id} and {name}.
This make sense? This is clearly related to how I'm joining the tables and the inclusion of the {comment_id) column in relationship to the DISTINCT statement but I can't seem to figure out how to get around this and at the data from exp_comment without screwing up my original intent.
If I remove c.comment_id and c.name from my SELECT the query performs as I want it to but I don't have the additional info I'm after.
Would anyone be able to lend a hand?
Thanks











Bookmarks