Trying to do query based on dates

They have: 426 posts

Joined: Feb 2005

Hi all, i am running an smf forum and now have decided to add a front page, where you can see the latest topics that have been posted. Part of the stats is when the last person made a post to that topic, whether it be a reply or the actual post itself.

The database has two tables: smf_messagas and smf_topics.

So how it works is all the posts including the actual start topic is in the messages table. The important fields being:

ID_TOPIC
posterTime

in smf_topics there are numerical stats like:

ID_LAST_MSG

The last mess matches the id topic to find the last message to the topic i cant get the sql.

This is what i have:

$query2="select m.ID_MSG, t.ID_LAST_MSG, m.posterTime from smf_messages as m, smf_topics as t where m.ID_MSG=t.ID_LAST_MSG order by m.posterTime LIMIT 10 desc";
'

On the off chance someone maybe able to help i need to incorporate it within the fisrt query which finds the last topic, number of replies and the user that started the topic, this query works fine.

$query ="SELECT t.ID_FIRST_MSG, t.ID_TOPIC, t.numReplies, t.ID_MEMBER_STARTED, m.posterTime, m.posterName, m.subject, m.ID_TOPIC, m.ID_MSG from smf_topics as t, smf_messages as m where t.ID_TOPIC=m.ID_TOPIC AND t.ID_FIRST_MSG=m.ID_MSG order by m.posterTime desc LIMIT 10";
'

I would be over the moon if someone could help. Yes i have tried the smf forums but they are adament to help becuase they have an ssi_lastTopics() function however the formating is not good and i wanted to try and write it myself.