문제

I have one question about query in Zend with this data:

+--------+-----------+
| Sender | Recipient |
+--------+-----------+
|   1010 |      1011 |
|   1011 |      1012 |
|   1011 |      1010 |
|   1012 |      1011 |
|   1012 |      1000 |
+--------+-----------+

If I query for 1010 the answer should be 1012, because 1010 is sender for recipient 1011 and 1011 is sender for recipient 1012:

1010->1011->1012

If input 1011 the answer should be 1011, 1000 and 1011:

1011->1012->1011,1000    
1011->1010->1011

How do I query in one line for Zend framework?

도움이 되었습니까?

해결책

Make a self-join:

$db->select()
->from(array('a' => 'my_table'), array())
->join(array('b' => 'my_table'), 'b.Sender = a.Recipient', array('Recipient'))
->where('a.Sender = ?', $id)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top