TechMistress Posted February 5, 2009 Share Posted February 5, 2009 Hello Everyone, I've got a snippet of code that is not resulting in what I want. I have 2 tables. table 1 is projects, holds project info and project_types (category ids) table 2 is categories, hold category ids and category names My snippet of code here is showing the category/project_type id instead of the category_name. What did I do wrong? SELECT p.project_types, c.cat_name FROM projects p LEFT JOIN categories c ON p.project_types = c.cat_id GROUP BY p.project_types ORDER BY c.cat_name ASC Link to comment https://forums.phpfreaks.com/topic/143967-solved-i-know-its-a-typo-can-someone-help-me-with-this/ Share on other sites More sharing options...
Maq Posted February 5, 2009 Share Posted February 5, 2009 That's impossible unless you think "project_types" is both of them... You have: SELECT p.project_types, c.cat_name which will only display "project_types" and "cat_name" but never "category_id". Link to comment https://forums.phpfreaks.com/topic/143967-solved-i-know-its-a-typo-can-someone-help-me-with-this/#findComment-755439 Share on other sites More sharing options...
TechMistress Posted February 5, 2009 Author Share Posted February 5, 2009 Hmm, I don't think I explained well. the project_type in TABLE "projects" is the same as cat_id in TABLE "categories". (don't ask me why it's labeled differently) I want to display the "cat_name" from TABLE "categories" who's "cat_id" matches the "project_type" of TABLE projects. I hope that's clearer. (hopefully not worse) Link to comment https://forums.phpfreaks.com/topic/143967-solved-i-know-its-a-typo-can-someone-help-me-with-this/#findComment-755539 Share on other sites More sharing options...
fenway Posted February 6, 2009 Share Posted February 6, 2009 Wait a minute... why project_types? Plural? What are you storing in there? Tell me it's not an array.... Link to comment https://forums.phpfreaks.com/topic/143967-solved-i-know-its-a-typo-can-someone-help-me-with-this/#findComment-755807 Share on other sites More sharing options...
TechMistress Posted February 6, 2009 Author Share Posted February 6, 2009 No, no arrays. It turns out the code worked fine - the problem was with my data. The categories were re-done, so the project_type id was a number that was no longer matching any cat_id from the other table, so I just saw the number. Thanks everyone for the comments! Link to comment https://forums.phpfreaks.com/topic/143967-solved-i-know-its-a-typo-can-someone-help-me-with-this/#findComment-756125 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.