0

I'm working on representing a Parent-Child Relationship in a Database. I"m not sure if it's something you're supposed to do, so I figured I'd ask. My idea is to have a table like this:

Parent Child
  1      2
  2      3
  3      4

Word that work? And if it does work, is it possible to use a recursive php function to get 1 from 4?

something like:

getancestor.php?child=4
{
 $parent = (mysql_query to get $parent)
if($parent != null)
{
 getancestor.php?child=$parent;
else
{
 return;
}
}

Please excuse my sloppy pseudo-code and thanks for the help!

4

0 回答 0