The Little Guy Posted July 17, 2008 Share Posted July 17, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/115164-returning-mysql-results/ Share on other sites More sharing options...
l0ve2hat3 Posted July 17, 2008 Share Posted July 17, 2008 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' Quote Link to comment https://forums.phpfreaks.com/topic/115164-returning-mysql-results/#findComment-592188 Share on other sites More sharing options...
The Little Guy Posted July 17, 2008 Author Share Posted July 17, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/115164-returning-mysql-results/#findComment-592497 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.