Jump to content

Returning MySQL Results


The Little Guy

Recommended Posts

I have this query:

SELECT
MainCategory.category as mc, 
MainCategory.description as md, 
MainCategory.edit as me, 
SubCategory.category as sc , 
SubCategory.edit as se 
FROM MainCategory, SubCategory 
WHERE MainCategory.category = '%s'
AND
MainCategory.id = SubCategory.MainCategoryID

 

I need it to return the main category, even if there is no subcategory(s). Currently because of the last line, if there is no subcategory, it returns nothing, but if there is a subcategory or more, it will return the results. how can I fix this?

Link to comment
https://forums.phpfreaks.com/topic/115164-returning-mysql-results/
Share on other sites

hrmmm maybe left join the tables

 

SELECT
MainCategory.category as mc, 
MainCategory.description as md, 
MainCategory.edit as me, 
SubCategory.category as sc , 
SubCategory.edit as se 
FROM MainCategory 
LEFT JOIN SubCategory ON SubCategory.MainCategoryID=MainCategory.id 
WHERE MainCategory.category = '%s'

Almost works, it grabs everything except for one column...

 

#id, MainCategoryID, category

1  	7  	Uploads
2 	7 	Downloads
3 	7 	Navigation
4 	7 	Email

If I were to run that code, Using the keyword 'Internet' (in place of the %s), I get all the results except for "Uploads".

See: http://iarepc.tzfiles.com/wiki/Internet

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.