title: How can I create a loop that can get 6 levels of parents?
body: <p>I am working on this page concept of pedigree. How can I foreach or create a loop that can get 6 levels of parents, for example <code>name= 1 ; nfather=2; nmohter = 3</code> and the loop continue to get or consider <code>nfather</code> as a <code>name = 2</code> and get his parents.</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>