在php和sql中编写关于数据库连接的伪代码

İ have a few topics which has different subtopics. İ want to load this subtopicswhen topics are choosen and i can do it.but the problem is some subtopics has different header while some have same header.how a program can decide which subtopic has which header.

Simple example: İ must load headers to the page then i should decide which subtopics has which header.

I have tree table in my db

  1. Topics and topics-id in table1
  2. Headers and headers-id and topic-name in table2
  3. Subtopics and subtopics-id and header-name in table3

edit my pseudocode is

If (subtopicid == headerid){go there}

If i can write 1==header id its okay but i need to get subtopic id at the same time from db.thats my real problem.i gues i cant say it more clear than that