Forum Moderators: coopster
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:
<?
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query0 = "select sire,dam,dob,horse from horse where id=$id";
$numresults0=mysql_query($query0);
$numrows0=mysql_num_rows($numresults0);
$result0 = mysql_query($query0) or die("Error - Results 0");
$sire1=mysql_result($result0,$i,"sire");
$dam1=mysql_result($result0,$i,"dam");
$horse0=mysql_result($result0,$i,"horse");
$dob0=mysql_result($result0,$i,"dob");
echo "$dob0";
echo "$horse0";
echo "<br><br>";
$query1 = "select id from horse where horse=\"$sire1\"";
$result1 = mysql_query($query1) or die("Result1");
$id1=mysql_result($result1,$i,"id");
$query2 = "select sire,dam,dob,horse from horse where id=$id1";
$result2 = mysql_query($query2) or die("Bad Error");
$sire2=mysql_result($result2,$i,"sire");
$dam2=mysql_result($result2,$i,"dam");
$horse1=mysql_result($result2,$i,"horse");
$dob1=mysql_result($result0,$i,"dob");
echo "$dob1";
echo "$horse1";
?>