title: Pedigree/Family tree chart from database
body: <p>I am trying to generate pedigree (in other words family tree :) ) table from database...</p>
  
  <p>My schema:</p>
  
  <pre><code>CREATE TABLE `horses` ( 
  `horse_id` int(10) NOT NULL AUTO_INCREMENT,
  `horse_name` varchar(32) NOT NULL,
  `horse_sire` int(10) DEFAULT NULL,
  `horse_dam` int(10) DEFAULT NULL, 
  PRIMARY KEY (`horse_id`),
  KEY `FKsire` (`horse_sire`),
  KEY `FKdam` (`horse_dam`),
  CONSTRAINT `FKdam` FOREIGN KEY (`horse_dam`) REFERENCES `horses` (`horse_id`),
  CONSTRAINT `FKsire` FOREIGN KEY (`horse_sire`) REFERENCES `horses` (`horse_id`)
  )
  </code></pre>
  
  <p>p.s. 'horse_dam' and 'horse_sire' represents parents...
  I have spent days on this problem, searching, experimenting... 
  And currently I have this partly solution:</p>
  
  <pre><code>display_children($selected_horse_id, 5);
  
          function display_children($parent, $level) {
              mysql_connect('localhost','root','');
              mysql_select_db('hdb');
              $result = mysql_query('SELECT * FROM horses WHERE horse_id="'.$parent.'";');
  
  
              while ($row = mysql_fetch_array($result)) {
  
                  echo "&lt;tr&gt;&lt;td&gt;";
                  echo $row['horse_name'];
                  echo "&lt;/td&gt;&lt;/tr&gt;";
  
                  display_children($row['horse_dam'], $level+1);
                  display_children($row['horse_sire'],$level+1);
              }
          }
  </code></pre>
  
  <p>which generates table in one row :( I cannot think of proper way to implement it...
  And the result I want is <a href="http://www.pedigreequery.com/malibu2" rel="nofollow">Pedigree Query</a></p>
  
  <p>Any help or hint is highly appreciated :),
  Thanks in advance</p>