Jump to content

Recommended Posts

Hey,

 

I have two tables, posts and threads.

 

I'm using a $_GET to determine which thread the user wants to view, so for example we want to see thread #3.

 

$getPosts = mysql_query("SELECT * FROM threads,posts WHERE threads.id=3 AND posts.thread_id=3 ORDER BY postdate ASC");

 

That is basically how it looks like right now, I've done inner joins before but completely forgot how to. But to sum up what I want done;

 

I want this thread to show the threadpost from the table 'threads' first, and then the posts from 'posts' for this thread following.

 

The posts have a column named 'thread_id' that if corresponding with the thread, will list the posts within the thread, meaning 'thread_id=3'

 

In both tables I have such things like author, postdate, message, ip, and etc etc, but only 'threads' table contains the column 'topic'

 

I know it looks pretty messy, I could just screw this idea and have both threads and posts in the same table, defining a post as a thread in a column and etc etc but I feel like trying this method.

 

Just ask if you got any questions, I'm sure I missed some information that needed to be told but it's messy as I said before.

 

Thanks!

SELECT t.`topic`,t.`author` AS `thread_author`, t.`postdate` AS `thread_postdate`, t.`message` AS `thread_message`, p.`author` AS `post_author`, p.`postdate` AS `post_postdate`, p.`message` AS `post_message` FROM `threads` as `t` LEFT JOIN `posts` AS `p` ON t.`id`=p.`thread_id` WHERE t.`id`=3

 

this will get a joined result of threads/posts with a thread ID of 3.

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.