Jump to content
xisto Community
Sign in to follow this  
suicide1405241470

Selection From Multiple Tables

Recommended Posts

I am in the middle of creating a little forums system, and all so far is going quite well. However I have come across a small problem;PHP:-------------------------------------------------------------------------------- $gather_forums_qry = "SELECT a.frm_id, a.frm_name, a.frm_description, count(distinct(b.fth_id)) ThreadCount, count(distinct(c.fpt_id)) PostCount, a.frm_enabled, IF( IFNULL( MAX( b.fth_dateposted), 0) > IFNULL( MAX( c.fpt_dateposted), 0), date_format( IFNULL( MAX( b.fth_dateposted), 0), '%d/%m/%Y %T'), date_format( IFNULL( MAX( c.fpt_dateposted), 0), '%d/%m/%Y %T')) AS topic_last_post, d.usr_id AS UserID, d.usr_name AS UserName FROM dm_forum a LEFT JOIN dm_forum_thread b ON ( a.frm_id = b.fth_forumid) LEFT JOIN dm_forum_post c ON ( b.fth_id = c.fpt_threadid) LEFT JOIN dm_users d ON ( d.usr_id = IF(IFNULL( b.fth_dateposted, 0) < IFNULL( c.fpt_dateposted, 0), b.fth_userid, c.fpt_userid)) WHERE a.frm_enabled = '1' GROUP BY a.frm_name";--------------------------------------------------------------------------------I am trying to get the username of the last user who posted. The above code gets the correct date/time of the last post, it just doesn't get the last username correctly. I know I am missing something, but can't see what.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.