Jump to content

Recommended Posts

I have the following query which selects all the info i need for the current page and displays it.

 

$topic_info_query = $db->query("SELECT 
								f.forum_id, f.forum_name,
								m.user_id, m.user_username, m.user_group,
								t.thread_topic_id, t.topic_name, t.topic_poster, t.topic_time_posted, t.topic_views,
								t.topic_replies, t.topic_last_poster, t.topic_last_post_time, t.topic_locked,
								t.topic_sticky, t.topic_edited

								FROM ".DB_PREFIX."topics as t

								LEFT JOIN ".DB_PREFIX."members as m
								ON t.topic_poster = m.user_username

								LEFT JOIN ".DB_PREFIX."forums as f
								ON t.forum_id = f.forum_id

								WHERE t.forum_id = '$forum_id'

								ORDER BY t.topic_last_post_time DESC")
								or trigger_error("SQL", E_USER_ERROR);

$topic_num_rows = mysql_num_rows($topic_info_query);

while ($topic_info = mysql_fetch_object($topic_info_query)) 

 

you can see the code working here: http://thevault.cz.cc/index.php?forum=4

 

However the last post section doesnt work.

This is because the LEFT JOIN which joins the members table is on the topic_starter.

but i cant add another join for the topic_last_poster cos they would go to the same thing user_username which wouldnt work.

 

so how do i retain the join for the topic_starter while somehow getting the last_poster to work?

 

I was under the assumption that i may have to create a new db table with seperate user information in but im not sure.

 

Link to comment
https://forums.phpfreaks.com/topic/217216-table-joins/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.