Page 1 of 1

Seperating into categories

Posted: Sun Aug 31, 2008 8:55 am
by josephman1988
Hey guys, I have script which associates 'guides' to 'games', then associates the 'guides' to 'categories'.

This query joins the 3 together and SHOULD only return category ids of '1'.
However, for some reason, if i have a guide that's in category '2' when running this query in phpMyAdmin it adds that guide aswell but the category id for it (gcId) is '1' for some reason.

So heres the query:

Code: Select all

SELECT guidesgamesconnect.gamesgId, guidesgamesconnect.guidesguId, guides.guTitle, guides.guName,  guides.guAuthor, guides.guDate,  guides.guVersion, guidescategories.gcName, guidescategories.gcId
FROM guidesgamesconnect, guidescategoriesconnect
LEFT JOIN guides  
ON guides.guId = guidesgamesconnect.guidesguId 
LEFT JOIN guidescategories
ON guidescategories.gcId = guidescategoriesconnect.guidescategoriesgcId
WHERE guidesgamesconnect.gamesgId = 71 and guidescategoriesconnect.guidescategoriesgcId= 1
 
These are the tables involved:

Code: Select all

============================================
|guId | guTitle | guName | guAuthor | guDate | guVersion |
============================================
|12    | fgdgsg |   10.txt   |  dgdfg   | 08-30  | fgdfgdfg   |
============================================
guidesgamesconnect

Code: Select all

===================
|gamesgId | guidesguId |
===================
|71          | 12            | 
===================
guides

Code: Select all

============================================
|guId | guTitle | guName | guAuthor | guDate | guVersion |
============================================
|12    | fgdgsg |   10.txt   |  dgdfg   | 08-30  | fgdfgdfg   |
============================================
Ok so these 2 are absolutely fine, if i didnt want to split these into categories i would have moved on. So now comes the problem.

New table structures
guidescategories

Code: Select all

==============
|gcId | gcName   |
==============
|1     | general    |
|2     | in-depth  |
|3     | general    |
==============
guidescategoriesconnect

Code: Select all

==========================
|guidesguId| guidescategoriesgcId| 
==========================
|12| 1                          |
|13| 2                          |
==========================
I basically want to have 3 queries on the same page separating them into 3 categories.
Thanks for any help in advance

Re: Seperating into categories

Posted: Wed Sep 03, 2008 1:47 pm
by andyhoneycutt
it could be because you're doing left joins. Try just "join" instead. Left implies you want all results from the table listed in the FROM statement.