I am looking to create a pedigree chart for dogs; I could hard code it but the b____ could have say 7 puppies which means I need to create 7 pages.
If I put the data into a database and create the chart dynamicaly its a lot neater and easier to update.
But I can not think of a good way to do the queries; below is what I have so far and on 2 generations its 5 queries but going up one more generation it becomes 13 queries and so on. I could continue this way and it is not to much work but is there a better way ?
Also using a function reduces the amount of code but as well as echoing the result I need to return the Sire & Dam values for the next queries.
<?php
// Display function NEED TO RETURN THE $row[Sire] AND $row[Dam] FOR THE NEXT LOOP
function display( $ref, $div )
{
$result = MYSQL_QUERY("SELECT * FROM pedigree WHERE ID_number = '$ref' ") or die ( mysql_error() );
$row = mysql_fetch_array( $result );
echo "<div class=\\"$div\\">Name: ". $row[Name] ."<br/>DOB: ". $row[DOB] ."<br/>Sex: ". $row[Sex] ."<br/>KC name: ". $row[KC_name] ."<br/>KC number: ". $row[KC_number]."<br/>Sire: ". $row[Sire]."<br/>Dam: ". $row[Dam]."</div>";
}
// Input the dogs ID from the URL - HARD CODED FOR NOW
// $ref = $_POST['ID'];
$ref = '1';
// Select details of dog from database
$result = MYSQL_QUERY("SELECT * FROM pedigree WHERE ID_number = '$ref' ") or die ( mysql_error() );
$row = mysql_fetch_array( $result );
echo "<div class=\\"first\\">Name: ". $row[Name] ."<br/>DOB: ". $row[DOB] ."<br/>Sex: ". $row[Sex] ."<br/>KC name: ". $row[KC_name] ."<br/>KC number: ". $row[KC_number]."<br/>Sire: ". $row[Sire]."<br/>Dam: ". $row[Dam]."</div>";
// Setup the variables for this dogs parents
// Need this or else the details are taken from whichever record is used next!
$sire_1 = $row[Sire];
$dam_1 = $row[Dam];
// Select all dogs relatives from the database
// Select details of the dog from database
if( !empty($sire_1) ){
$ref = $sire_1;
display( $ref, 'V');
}
// Select details of the ***** from database
if( !empty($dam_1) ){
$ref = $dam_1;
display( $ref, 'V');
}
?>