Results 1 to 2 of 2

Thread: MySQL Help

  1. #1
    misfortune Guest

    Question MySQL Help

    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.

  2. #2
    Join Date
    May 2009
    Location
    England
    Posts
    165
    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

    Regards,


    David

Similar Threads

  1. New Free MySQL GUI
    By expert-database in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 1
    Last Post: 21 Dec 2006, 05:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •