Jump to content

virtual pedigree


Tanja

Recommended Posts

I´m using this script to show pedigrees, works fine.

Now i want to show a virtual pedigree (for testmating or puppys).

For puppys i add a new table in database with id, father_id, mother_id. All other (living) dogs are in table dog (again with father and mother id). So this is working for dogs who are already in table dog:

             $sql = "SELECT a.father_id, a.mother_id, s.dogname, d.dogname
                     FROM dog a 
                        INNER JOIN dog s ON a.father_id = s.id
                        INNER JOIN dog d ON a.mother_id = d.id
                     WHERE a.id = '$dogid' ";

But my puppy isn´t in table dog... Is there a way to say get father and mother from puppy and then get all other generation from dog?

Link to comment
https://forums.phpfreaks.com/topic/275756-virtual-pedigree/
Share on other sites

SELECT a.father_id, a.mother_id, s.dogname, d.dogname
 FROM puppy a 
JOIN dog s ON a.father_id = s.id
JOIN dog d ON a.mother_id = d.id
 WHERE a.id = '$dogid'

all variations won´t work... With this statement i get father an mother (at right position) but no grandparents; for all empty ancestors i get resource(xx) of type (mysql result) 0.

With your postet statement i get Unknown column 'm.dogame' in 'field list'.

I think the problem is to switch between puppy and dog. First get mother_id(=dog.id) and father_id(=dog.id) from puppy and then switch to dog to get all other information and puppy.id can´t use in table dog, because maybe there is another dog with same id

Link to comment
https://forums.phpfreaks.com/topic/275756-virtual-pedigree/#findComment-1419104
Share on other sites

If you also need grandparents you need to do extra joins for both parents:

SELECT
c.dogname as child, m.dogame as mother, f.dogname as father,
mm.dogname as mother_mother, mm.dogname as mother_father
..
FROM puppy c
JOIN dog m ON c.mother_id = m.id
JOIN dog f ON c.father_id = f.id
LEFT JOIN dog mm ON m.mother_id = mm.id
LEFT JOIN dog mf ON m.father_id = mf.id
LEFT JOIN dog fm ON f.mother_id = fm.id
LEFT JOIN dog ff ON f.father_id = ff.id
WHERE c.id = '$dogid';
Link to comment
https://forums.phpfreaks.com/topic/275756-virtual-pedigree/#findComment-1419109
Share on other sites

You could try this

 

Add an extra parameter to the PrintTree() function

 

 

function printTree($dogid, $name, $N, $max, $virtual=0) {
 
    ...
    $tablename =  ($virtual && $N==0) ? 'puppy' : 'dog';
 
    $sql = "SELECT a.father_id, a.mother_id, s.dogname, d.dogname
    FROM $tablename a 
    JOIN dog s ON a.father_id = s.id
    JOIN dog d ON a.mother_id = d.id
    WHERE a.id = '$dogid' ";
 
    ...
}

 

Call function with virtual set to 1 for the puppies

Link to comment
https://forums.phpfreaks.com/topic/275756-virtual-pedigree/#findComment-1419129
Share on other sites

Version of ignace : can I use this solution in my script? I don´t think so...

Version of Barand: will give me id of puppy, but all other id´s are empty....

 

What about call this script two times (one for father, one for mother)?

All we be shown, but i have two tables with unequal witdhs. I comment out the pictures. Can I put them together in one table?

$maleid = $row['fatherid'];
$malename=$row['father'];


function printTreemale($maleid, $malename, $N, $max) {

         if ($malename == '') $malename = ' ';

         // calculate how many rows the cell should span

         $rspan = pow(2, $max-$N);
			//start	 für bild existiert
		// if(file_exists("photo/".$maleid."/".$maleid.".jpg"))
		// $img = "photo/".$maleid."/".$maleid.".jpg";
			// else
		// $img = "platzhalter.png";
		//ende	
		$malename = "<a href='dog.php?id=$maleid'>$malename</a>";  
         if ($rspan > 1)
             echo "\t<td rowspan='$rspan' >$malename</td>\n";
         else
             echo "\t<td>$malename</td>\n";

         // check for last cell in row
         if ($N == $max) echo "</tr>\n<tr>\n";

         // print parent trees, sire then dam
         if ($N < $max) {
             $sql = "SELECT a.father_id, a.mother_id, s.dogname, d.dogname
                     FROM dog a 
                        INNER JOIN dog s ON a.father_id = s.id
                        INNER JOIN dog d ON a.mother_id = d.id
                     WHERE a.id = '$maleid' ";
             $res = mysql_query($sql);
             list($s, $d, $sn, $dn) = mysql_fetch_row($res);
             printTreemale($s, $sn, $N+1, $max);
             printTreemale($d, $dn, $N+1, $max);
         }
}

function pedigreemale($maleid, $malename) {
//$generation = (int)($_GET['gens']);
  if(!isset($_GET['gens'])) {
    $generation = "3";  } 

  else {
    $generation = (int)($_GET['gens']);  }	
	
    echo "<TABLE border='1' width='100%'>\n";
    echo "<tr>\n";
    echo "</tr>\n<tr>\n";

    printTreemale($maleid, $malename, 0, $generation);

    echo "</tr>\n</TABLE>\n";

}


$femaleid = $row['motherid'];
$femalename=$row['mother'];


function printTreefemale($femaleid, $femalename, $N, $max) {

         if ($femalename == '') $femalename = ' ';

         // calculate how many rows the cell should span

         $rspan = pow(2, $max-$N);
			//start	 für bild existiert
		// if(file_exists("photo/".$femaleid."/".$femaleid.".jpg"))
		// $img = "photo/".$femaleid."/".$femaleid.".jpg";
			// else
		// $img = "platzhalter.png";
		//ende	
		$femalename = "<a href='dog.php?id=$femaleid'>$femalename</a>
		
		";  
         if ($rspan > 1)
             echo "\t<td rowspan='$rspan' >$femalename</td>\n";
         else
             echo "\t<td>$femalename</td>\n";

         // check for last cell in row
         if ($N == $max) echo "</tr>\n<tr>\n";

         // print parent trees, sire then dam
         if ($N < $max) {
             $sql = "SELECT a.father_id, a.mother_id, s.dogname, d.dogname
                     FROM dog a 
                        INNER JOIN dog s ON a.father_id = s.id
                        INNER JOIN dog d ON a.mother_id = d.id
                     WHERE a.id = '$femaleid' ";
             $res = mysql_query($sql);
             list($s, $d, $sn, $dn) = mysql_fetch_row($res);
             printTreefemale($s, $sn, $N+1, $max);
             printTreefemale($d, $dn, $N+1, $max);
         }
}

function pedigreefemale($femaleid, $femalename) {
//$generation = (int)($_GET['gens']);
  if(!isset($_GET['gens'])) {
    $generation = "3";  } 

  else {
    $generation = (int)($_GET['gens']);  }	
	
    echo "<TABLE border='1' width='100%'>\n";
    echo "<tr>\n";
    echo "</tr>\n<tr>\n";

    printTreefemale($femaleid, $femalename, 0, $generation);

    echo "</tr>\n</TABLE>\n";

}



pedigreemale($maleid, $malename);
pedigreemale($femaleid, $femalename);
Link to comment
https://forums.phpfreaks.com/topic/275756-virtual-pedigree/#findComment-1419174
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.