MySql selecting column via other table
This one is quite difficult to explain, so i'll give it a try.
I have a forum working like this:
sections>categories>topics>posts
each section has it own premission level 1 2 3 or 4.
it works with direct url, but ofcourse if someone goes to the direct url it needs to check its premissions.
So topic ID 3 is in categorie id 2 , and categorie ID 2 is in the section ID 1 (for example).
so how do i check the premission, i got something like this, but ofcourse im stuck now.
SELECT forum_section.section_level FROM forum_section WHERE forum_categorie.categori开发者_如何学Pythone_section_id = "Here the select categorie ID needs to go???"
if I am unclear please say so, and i'll try to post the code im working with, and the complete table layout.
Thanks in advance.
I quess you are storing the categorie ID in the topic table and section ID in category table
So use join ...
SELECT forum_section.section_level FROM forum_topic
LEFT JOIN
forum_category ON forum_topic.topic_category_id = forum_category.category_id
LEFT JOIN
forum_section ON forum_category.category_section_id = forum_section.section_id
WHERE
forum_topic = 'Forum topic ID';
You have to tell the server how to join the 2 tables
For example
SELECT forum_section.section_level
FROM forum_section, forum_categorie
WHERE forum_section.cat_id = forum_categorie.cat_id
AND forum_categorie.categorie_section_id = "Here the select categorie ID needs to go???"
Assuming cat_id
is the column that joins the tables (I don't know what it is called or if it even exists in your case).
精彩评论