从数据库获取分层格式的From-To Fields

I have MySQL table as below. In which have 2 fields. From and To. (and my code is in PHP).

Id    |From    |To
------|--------|--------
1     |1       |2
2     |2       |4
3     |3       |4
4     |4       |5
5     |4       |6
6     |5       |7
7     |6       |8
8     |8       |9

Now to get Graph kind thing as HTML output, Is there any way to give representation like I am expecting in as few as possible MySQL query?

1 ----- 2     5 ----- 7
         \   /
          \ /
           4
          / \
         /   \
        3     6 ----- 8 ----- 9

What I am doing now is, If I search Graph for "4", first I will get all backward points and then move ahead to get all forward points.