PDA

View Full Version : MySQL Help



misfortune
22 May 2009, 07:54 PM
This is a bit hard to explain but I will try.

I have a table named forum that has a column called 'bid' and one called 'fid'. Both columns are all numbers. bid stands for board ID. My PHP code holds a bid var. I need to get all of the different 'fid' numbers depending on what my $bid var holds and then count all of the rows in another table called "poster" where the different "fid"s in the first table are equal to the "topicID"s in the second table. The end result would be a number.

Thanks in advance if you are able to help.

dmcleary
29 May 2009, 03:00 AM
Hello Misfortune.

I think we'll need a little more description to solve it but here's my reply which might or might not fit.

For a basic select you have:

SELECT * FROM forum WHERE bid = $bid ORDER BY id ASC

What I think you're trying to do is to pull information into the response from a second table. To do that you need to do a JOIN. Now it depends what MySQL you're running but this is the kind of thing you should be looking at:

SELECT forum.*, poster.* FROM forum JOIN poster ON (forum.fid = poster.topicID) WHERE forum.bid = $bid ORDER BY forum.id ASC

The thing to note is that the field references are now preceded by the table name. You also need to ensure that you have two fields (one in each table) that allow you to connect the two tables - this is the relationship.

Please do re-post if I've not hit this particular nail on the head :D

Regards,


David