/    Sign up×
Community /Pin to ProfileBookmark

Probably a MySQL Join problem :)

Hi all!

I’ve got a forum I wrote my self. I’ve got these two tables:

[code=php]
forums_threads
`id` int(150) NOT NULL auto_increment,
`title` varchar(75) NOT NULL default ”,
`text` text NOT NULL,
`user_id` int(50) NOT NULL default ‘0’,
`views` int(75) NOT NULL default ‘0’,
`date` datetime NOT NULL default ‘0000-00-00 00:00:00’,
`lastpost` datetime default ‘0000-00-00 00:00:00’,
`active` tinyint(1) NOT NULL default ‘1’
[/code]

[code=php]
forums_replies
`id` int(50) NOT NULL auto_increment,
`tid` int(125) NOT NULL default ‘0’,
`text` text NOT NULL,
`user_id` int(50) NOT NULL default ‘0’,
`date` datetime NOT NULL default ‘0000-00-00 00:00:00’,
`active` tinyint(1) NOT NULL default ‘1’
[/code]

What I want to do is to display the top 5 posts on the forums. I can display from “forums_threads” with no problem just using ‘LIMIT’ but then I don’t get all the replies. I can also display from “forums_replies” with no problem using ‘LIMIT’ but then I don’t get a new thread that hasn’t gotten any replies.

How can I display the top 5 posts over all the forum, both new threads and replies?

Thanks,
Magnus

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@AnotherTechGuyDec 14.2007 — I guess tid in forum_replies is the thread id in the other table?

So you want to select the last 5 threads and also their replies, joining on tid and id ?

Just confirm that if you can mate...
Copy linkTweet thisAlerts:
@trymbillauthorDec 14.2007 — Yes, exactly! I am quite new at "joining" in MySQL ?
×

Success!

Help @trymbill spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...