Say I have a table with two columns... integers named "foo" and "bar" will work just fine. The primary key is both columns. Here's some sample data:
foo/bar
1/1
1/4
1/5
2/2
2/3
3/6
3/7
4/4
4/5
4/8
5/8
5/9
5/10
Now let's say any two rows with the same value of "bar", as well as any two rows with the same value of "foo", are connected. In this example, foo 1 is bar 1, 4, and 5... which means it's connected to foo 4 (by bar 4 and 5), and then foo 4 is connected to foo 5 (by bar 8). so foo 1, 4 and 5 are all connected. foo 2 and foo 3 stand alone. make sense?
How would I write a query that would return all the values (of either foo or bar; ideally both) that are connected in this way? If it's not possible, then what's the easiest way in PHP? Would I -need- to write a recursive function?