Jump to content

[SOLVED] I know it's a typo - can someone help me with this?


Recommended Posts

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

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".

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)

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.