#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2007
    Posts
    31
    Rep Power
    7

    Still having a problem with JOIN - returning wrong row for "ID"


    Hi again everyone.

    I am still having a massive issue with this join query, what I am trying is not working. If someone could point me in the right direction, I would greatly appreciate it.

    I have 2 tables: facts & favorites.

    I need ALL the data from facts (facts.ID, facts.body, facts.img ...etc)

    On the favorites table, there are only 3 columns:

    ID (which is also a column name in the facts table)
    userID
    factID (which = ID in facts table)

    What I am trying to accomplish is displaying all the facts that a user has favorited.

    For example, if the user likes fact #7, in the table "favorites", it would be:

    ID=1 (primary, auto inc)
    userID = (ID of the USER)
    factID = 7 (ID of the fact)

    I know I have to use a join somehow, but every time I have tried, when I echo $row['ID'], I need that to be the facts.ID, not favorites.ID, which is what it is displaying. How would I write the query so that $row['ID'] shows the ID # from the FACTS table?

    I hope I explained that well enough, feel free to ask Q's if not.

    Thank you!
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,965
    Rep Power
    9397

IMN logo majestic logo threadwatch logo seochat tools logo