获取多对多关系表数据[关闭]

I was trying to fetch data from following tables.

table_question

q_id | question     
 1   |   q1   
 2   |   q2
 3   |   q3  
 4   |   q4   

table_answer

a_id| answer 
 1   |   a1   
 2   |   a2
 3   |   a3  
 4   |   a4    
 5   |   a5

table_entity

e_id| q_id | a_id 
1   |   1  |    1 
2   |   1  |    3
3   |   2  |    2
4   |   2  |    4
5   |   3  |    5
6   |   4  |    2

I want a question and answer. Please give me some suggestion. Fetche data by using doctorine 2 ORM.

Try this mysql with your phpmyadmin

$qry = "SELECT quetion.que,answer.ans FROM entity INNER JOIN quetion ON quetion.id=entity.q_id Inner Join answer On answer.id=entity.a_id";

There are use join table for join those table and get the data from those table

you need to use join query. With joining both table you can get all tables relational data

 $query = SELECT table_question.question,table_answer.answer FROM table_entity INNER JOIN table_question ON table_question.id=table_entity.`q_id ` Inner Join table_answer On table_answer.id=table_entity.a_id ;

Here you go:

SELECT table_question.question, table_answer,answer FROM table_entity
JOIN table_question ON (table_entity.q_id = table_question.q_id)
JOIN table_answer ON (table_entity.a_id = table_answer.a_id)