Seperating into categories

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
josephman1988
Forum Newbie
Posts: 15
Joined: Mon Apr 21, 2008 8:29 am

Seperating into categories

Post 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
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: Seperating into categories

Post 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.
Post Reply