tags:

views:

31

answers:

1

In my forum that I am building, I want to get information about users that make the posts in a thread. For example, a signature, their forum rank, number of posts, etc, from a table, ForumSettings. I have the list of threads in a table with an ID, and I have the posts in a separate table with a threadID column that links to the ThreadList table. Using PHP, how can I EFFICIENTLY get info about a user to display next to each post they make?

+1  A: 

Say you are loading the thread with id = 5

SELECT u.`name`, u.`signature`, u.`rank`, COUNT(*) as numPosts
FROM `users` u INNER JOIN `posts` p ON (u.`id` = p.`userId`)
WHERE u.`id` IN (
    SELECT `userId` FROM `posts` WHERE `threadId` = 5
)
GROUP BY u.`name`, u.`signature`, u.`rank`
nickf