How can I join 3 tables with mysql & php?

Posted by steven on Stack Overflow See other posts from Stack Overflow or by steven
Published on 2010-06-19T21:39:07Z Indexed on 2011/11/20 9:50 UTC
Read the original article Hit count: 172

Filed under:
|
|
|
|

check out the page [url]http://www.mujak.com/test/test3.php[/url]

It pulls the users Post,username,xbc/xlk tags etc which is perfect... BUT since I am pulling information from a MyBB bulletin board system, its quite different. When replying, people are are allowed to change the "Thread Subject" by simplying replying and changing it.

I dont want it to SHOW the changed subject title, just the original title of all posts in that thread.

By default it repies with "RE:thread title". They can easily edit this and it will show up in the "Subject" cell & people wont know which thread it was posted in because they changed their thread to when replying to the post.

So I just want to keep the orginial thread title when they are replying.

Make sense~??

Tables:mybb_users Fields:uid,username

Tables:mybb_userfields Fields:ufid

Tables:mybb_posts Fields:pid,tid,replyto,subject,ufid,username,uid,message

Tables:mybb_threads Fields:tid,fid,subject,uid,username,lastpost,lastposter,lastposteruid

I haev tried multiple queries with no success:

$result = mysql_query("
    SELECT * FROM mybb_users
    LEFT JOIN (mybb_posts, mybb_userfields, mybb_threads)
    ON (
        mybb_userfields.ufid=mybb_posts.uid
        AND mybb_threads.tid=mybb_posts.tid
        AND mybb_users.uid=mybb_userfields.ufid
    )
    WHERE mybb_posts.fid=42");


$result = mysql_query("
    SELECT * FROM mybb_users
    LEFT JOIN (mybb_posts, mybb_userfields, mybb_threads)
    ON (
        mybb_userfields.ufid=mybb_posts.uid
        AND mybb_threads.tid=mybb_posts.tid
        AND mybb_users.uid=mybb_posts.uid
    )
    WHERE mybb_threads.fid=42");

$result = mysql_query("
    SELECT * FROM mybb_posts 
    LEFT JOIN (mybb_userfields, mybb_threads) 
    ON (
        mybb_userfields.ufid=mybb_posts.uid
        AND mybb_threads.tid=mybb_posts.tid
    )
    WHERE mybb_posts.fid=42");

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql