I don't know how good this info is, but you can order by 2 things at the same time. You can order by the topic_time, then order by the topic_id. Such is:
PHP Code:
ORDER BY topic_time, topic_id
What it sounds like you really want is the group function of mySQL. With that you can group those of the same value together. So:
PHP Code:
GROUP BY topic_id
Would give you the topic_ids all together, then you can sort by topic time.. so try this out for size:
PHP Code:
SELECT topic_id FROM posts GROUP BY topic_id ORDER BY topic_time DESC
That should do everything. But you are going to want to look out for private forums, and other things you don't want it to catch. That should put you out where you need to be.. but I think you should also check out
http://www.phpbbhacks.com/ for these types of things. (There is a most recent topics on any page type of code on there).