2 blueyed Nov 09, 2006 21:18

well i want to be able to sort the posts by;
the post's date
or the post's last comment date
depending on which one is more recent.
Then try it with IF() in the SQL to select the higher of the two and than order by that field/alias.
There should be really no need to duplicate this info!
:( but i would have no idea how to do this in sql...
How about
SELECT IF( comments.datetime > items.datetime, comments.datetime, items.datetime ) AS order_datetime, other, fields
FROM comments INNER JOIN items ON comments.item_ID = items.ID
ORDER BY order_datetime
for a start? :)
That's all pseudo and might not work, but something like that should do it.
Ok i made
SELECT IF( `evo_comments`.`comment_date` > `evo_posts`.`post_datecreated` , `evo_comments`.`comment_date` , `evo_posts`.`post_datecreated` ) AS `order_date` , `evo_posts`. *
FROM `evo_posts`
INNER JOIN `evo_comments` ON `evo_comments`.`comment_post_ID` = `evo_posts`.`post_ID`
ORDER BY `order_date` DESC
LIMIT 0 , 30
Except, it has duplicate results....
Changing it to a LEFT JOIN works fine, i have no idea what the different types of joins do, but it appears to work with LEFT...
SELECT IF( `evo_comments`.`comment_date` > `evo_posts`.`post_datecreated` , `evo_comments`.`comment_date` , `evo_posts`.`post_datecreated` ) AS `order_date` , `evo_posts`. *
FROM `evo_posts`
LEFT JOIN `evo_comments` ON `evo_comments`.`comment_post_ID` = `evo_posts`.`post_ID`
ORDER BY `order_date` DESC
LIMIT 0 , 30
Ok blueyed, how would i go about getting the posts to order like this when using a particular skin?
See the ItemList(2) class. You would have to inject the SQL there probably somehow. Probably only the additional SELECT and ORDER BY.
I fear, it's not possible without touching the class itself and may be more hackier with ItemList, which gets used in 1.8.x as with ItemList2, which gets used since 1.9 IIRC.
Sorry..
So what about hacking up the core, so it does not create a itemlist if this certain skin/plugin is used.
And then i just have a while(getrecord) $Posts[$row['post_ID']] = new Post($row['post_ID']);
well along those lines...
Looking at it now, i could just hack up the "Get ID list for Item List (Main|Lastpostdate)" Query...
Any reasons why this would not work?
Yes, the "Get ID list for Item List (Main|Lastpostdate)" query seems to be the one to hack to death.. ;)
You should be able to just get the last comment of an item from T_comments directly, ordering by date, shouldn't you?