Welcome to WebmasterWorld Guest from 22.214.171.124
The site is a database of horses with colunms of ID, Horse Name, DOB, Sex, Sire & Dam.
Now for each horse i would like a page that shows the sires and dams back a few generations - like a family tree.
Now i have no problem be able to display the Sire and Dam of a horse but i am not sure how i go about finding the sire and dam of this sire and so on to create the family tree. Much like this page - <removed> I know that this uses PHP Ged view but i dont want anything quite that complicated.
All horses are contained in the same table and for some there might not even be enough data to create the full family tree back say 3 generations so i would need to print a '?' or something.
How would it be best to achive this - would it involve multiple queries?
[edited by: jatar_k at 8:25 pm (utc) on Sep. 21, 2004]
[edit reason] removed url [/edit]
I'd suggest creating a function that grabs the information about the horse, including the Mommy & Daddy horses id's, when supplied the id. (Then, of course, just call the function again with the ancestor's id.)
A "real" programmer might bring up that this is a good job for recursion but it'd be a little tricky presenting the data attractively.
Here is code, ive included num_row because when i make it up properly i will use this in a if else statement to print something when there is no results:
@mysql_select_db($database) or die( "Unable to select database");
$query0 = "select sire,dam,dob,horse from horse where id=$id";
$result0 = mysql_query($query0) or die("Error - Results 0");
$query1 = "select id from horse where horse=\"$sire1\"";
$result1 = mysql_query($query1) or die("Result1");
$query2 = "select sire,dam,dob,horse from horse where id=$id1";
$result2 = mysql_query($query2) or die("Bad Error");