needing help with distinct function
Posted: Sun Aug 13, 2006 6:55 pm
I am building a database of pedigree of dogs but there is one thing i can't solve.
I want to build a sibling page and that is no problem untill i want to display distinct females and there offsprings with the same sire.
If I do a query to find out witch are the distinct mothers i get unique numbers and he will display them, but i want him to work with the numbers found with distinct function and give me names and offspring.
the output has to be in a formatted html table.
example: row1 female1
row2 offsprings of female1
untill the result of the distinct = 0
The result for the moment is found at http://www.wanyika.be/test/sibling.php?Id=7036
The code i have using untill now for this page is that below.
Now i want him to display below the females and there offsprings. Is there someone ho wants to help me solve this becomming nightmare?
I want to build a sibling page and that is no problem untill i want to display distinct females and there offsprings with the same sire.
If I do a query to find out witch are the distinct mothers i get unique numbers and he will display them, but i want him to work with the numbers found with distinct function and give me names and offspring.
the output has to be in a formatted html table.
example: row1 female1
row2 offsprings of female1
untill the result of the distinct = 0
The result for the moment is found at http://www.wanyika.be/test/sibling.php?Id=7036
The code i have using untill now for this page is that below.
Now i want him to display below the females and there offsprings. Is there someone ho wants to help me solve this becomming nightmare?
Code: Select all
<?php
include('config.php');
$Id = (isset($_GET['Id'])) ? intval($_GET['Id']) : 0 ;
$where = ($Id != 0) ? " WHERE Id=".$Id : " ";
$SQL_single = "SELECT * FROM dog_table WHERE Id = '".$Id."'" or die(mysql_error());
$SQL_single_Result = mysql_query($SQL_single);
$SQL_single_Row = mysql_fetch_array($SQL_single_Result);
$SQL_parents = "SELECT FatherId, MotherId FROM dog_table WHERE Id = '".$Id."'" or die(mysql_error());
$SQL_parents_Result = mysql_query($SQL_parents);
if ($SQL_parents_Result) {
$row = mysql_fetch_assoc($SQL_parents_Result);
$MotherId = $row['MotherId'];
$FatherId = $row['FatherId'];
}
else {
echo $SQL_parents;
}
$SQL_father = "SELECT * FROM dog_table WHERE Id = $FatherId" or die(mysql_error());
$SQL_father_Result = mysql_query($SQL_father);
$SQL_father_Row = mysql_fetch_array($SQL_father_Result);
$SQL_mother = "SELECT * FROM dog_table WHERE Id = $MotherId" or die(mysql_error());
$SQL_mother_Result = mysql_query($SQL_mother);
$SQL_mother_Row = mysql_fetch_array($SQL_mother_Result);
$SQL_full_Sibling = "SELECT * FROM dog_table WHERE FatherId = $FatherId AND MotherId = $MotherId and Id !=$Id";
$SQL_full_Sibling_Result = mysql_query($SQL_full_Sibling) or die(mysql_error());
$SQL_full_Sibling_Row = mysql_fetch_array($SQL_full_Sibling_Result);
function Print_Single ($SQL_single_Row) {
$Id = $SQL_single_Row['Id'];
$DOB1 = $SQL_single_Row['DOB'];
$DOB = date('d M Y', strtotime($DOB1));
$Image_folder = "<img src=\"../pictures/andere/new.gif\" width=\"35\" height=\"15\" />";
$new = $Image_folder;
$bewerk_datum = $SQL_single_Row['DOC'];
$aantal_dagen = floor(abs((strtotime($bewerk_datum)-time())/(60*60*24)));
$Image_folder2 = "<img src=\"../pictures/andere/update.gif\" width=\"47\" height=\"10\" />";
$update = $Image_folder2;
$bewerk_datum2 = $SQL_single_Row['DOU'];
$aantal_dagen2 = floor(abs((strtotime($bewerk_datum2)-time())/(60*60*24)));
print "<span class=\"style2\">".$SQL_single_Row['Ch']."</span>\n";
print "</a> ";
print "<span class=\"style3\">".$SQL_single_Row['DogName']."</span";
print "</a> ";
print "<span class=\"style4\">(".$SQL_single_Row['Color'].")</span>";
print "</a> ";
print "<span class=\"style4\">".$DOB."</span>";
print "</a>   ";
if($aantal_dagen <60){echo $new;}
else{echo'';}
if($aantal_dagen2 <60){echo $update;}
else{echo'';}
print "<br><font color='black' size='1' face='Arial'>";
print "[<a href=\"pedigree.php?Id=$Id\">Pedigree]</a> ";
print "[<a href=\"breeding.php?Id=$Id\">Breeding]</a> ";
print "[<a href=\"sibling.php?Id=$Id\">Sibling]</a></font>";
}
function Print_Father ($SQL_father_Row){
$Id = $SQL_father_Row['Id'];
$DOB1 = $SQL_father_Row['DOB'];
$DOB = date('d M Y', strtotime($DOB1));
$Image_folder = "<img src=\"../pictures/andere/new.gif\" width=\"35\" height=\"15\" />";
$new = $Image_folder;
$bewerk_datum = $SQL_father_Row['DOC'];
$aantal_dagen = floor(abs((strtotime($bewerk_datum)-time())/(60*60*24)));
$Image_folder2 = "<img src=\"../pictures/andere/update.gif\" width=\"47\" height=\"10\" />";
$update = $Image_folder2;
$bewerk_datum2 = $SQL_father_Row['DOU'];
$aantal_dagen2 = floor(abs((strtotime($bewerk_datum2)-time())/(60*60*24)));
print "<span class=\"style2\">".$SQL_father_Row['Ch']."</span>\n";
print "</a> ";
print "<span class=\"style3\">".$SQL_father_Row['DogName']."</span";
print "</a> ";
print "<span class=\"style4\">(".$SQL_father_Row['Color'].")</span>";
print "</a> ";
print "<span class=\"style4\">".$DOB."</span>";
print "</a>   ";
if($aantal_dagen <60){echo $new;}
else{echo'';}
if($aantal_dagen2 <60){echo $update;}
else{echo'';}
print "<br><font color='black' size='1' face='Arial'>";
print "[<a href=\"pedigree.php?Id=$Id\">Pedigree]</a> ";
print "[<a href=\"breeding.php?Id=$Id\">Breeding]</a> ";
print "[<a href=\"sibling.php?Id=$Id\">Sibling]</a></font>";
}
function Print_Mother ($SQL_mother_Row){
$Id = $SQL_mother_Row['Id'];
$DOB1 = $SQL_mother_Row['DOB'];
$DOB = date('d M Y', strtotime($DOB1));
$Image_folder = "<img src=\"../pictures/andere/new.gif\" width=\"35\" height=\"15\" />";
$new = $Image_folder;
$bewerk_datum = $SQL_mother_Row['DOC'];
$aantal_dagen = floor(abs((strtotime($bewerk_datum)-time())/(60*60*24)));
$Image_folder2 = "<img src=\"../pictures/andere/update.gif\" width=\"47\" height=\"10\" />";
$update = $Image_folder2;
$bewerk_datum2 = $SQL_mother_Row['DOU'];
$aantal_dagen2 = floor(abs((strtotime($bewerk_datum2)-time())/(60*60*24)));
print "<span class=\"style2\">".$SQL_mother_Row['Ch']."</span>\n";
print "</a> ";
print "<span class=\"style3\">".$SQL_mother_Row['DogName']."</span";
print "</a> ";
print "<span class=\"style4\">(".$SQL_mother_Row['Color'].")</span>";
print "</a> ";
print "<span class=\"style4\">".$DOB."</span>";
print "</a>   ";
if($aantal_dagen <60){echo $new;}
else{echo'';}
if($aantal_dagen2 <60){echo $update;}
else{echo'';}
print "<br><font color='black' size='1' face='Arial'>";
print "[<a href=\"pedigree.php?Id=$Id\">Pedigree]</a> ";
print "[<a href=\"breeding.php?Id=$Id\">Breeding]</a> ";
print "[<a href=\"sibling.php?Id=$Id\">Sibling]</a></font>";
}
function Print_full_Sibling ($SQL_full_Sibling_Row){
$Id = $SQL_full_Sibling_Row['Id'];
$DOB1 = $SQL_full_Sibling_Row['DOB'];
$DOB = date('d M Y', strtotime($DOB1));
$Image_folder = "<img src=\"../pictures/andere/new.gif\" width=\"35\" height=\"15\" />";
$new = $Image_folder;
$bewerk_datum = $SQL_full_Sibling_Row['DOC'];
$aantal_dagen = floor(abs((strtotime($bewerk_datum)-time())/(60*60*24)));
$Image_folder2 = "<img src=\"../pictures/andere/update.gif\" width=\"47\" height=\"10\" />";
$update = $Image_folder2;
$bewerk_datum2 = $SQL_full_Sibling_Row['DOU'];
$aantal_dagen2 = floor(abs((strtotime($bewerk_datum2)-time())/(60*60*24)));
print "<span class=\"style2\">".$SQL_full_Sibling_Row['Ch']."</span>\n";
print "</a> ";
print "<span class=\"style3\">".$SQL_full_Sibling_Row['DogName']."</span>";
print "</a> ";
print "<span class=\"style4\">(".$SQL_full_Sibling_Row['Color'].")</span>";
print "</a> ";
print "<span class=\"style4\">".$DOB."</span>";
print "</a>   ";
if($aantal_dagen <60){echo $new;}
else{echo'';}
if($aantal_dagen2 <60){echo $update;}
else{echo'';}
print "<br><font color='black' size='1' face='Arial'>";
print "  [<a href=\"pedigree.php?Id=$Id\">Pedigree]</a> ";
print "[<a href=\"breeding.php?Id=$Id\">Breeding]</a> ";
print "[<a href=\"sibling.php?Id=$Id\">Sibling]</a></font>";
}
function Print_distinct_mother ($SQL_distinct_mother_Row){
$sql = "SELECT * FROM dog_table WHERE Id = $Mother";
$Mother_Result = mysql_query($sql);
$Mother_Row = mysql_fetch_array($Mother_Result);
$Id = $Mother_Row['Id]'];
$DOB1 = $Mother_Row['DOB'];
$DOB = date('d M Y', strtotime($DOB1));
$Image_folder = "<img src=\"../pictures/andere/new.gif\" width=\"35\" height=\"15\" />";
$new = $Image_folder;
$bewerk_datum = $Mother_Row['DOC'];
$aantal_dagen = floor(abs((strtotime($bewerk_datum)-time())/(60*60*24)));
$Image_folder2 = "<img src=\"../pictures/andere/update.gif\" width=\"47\" height=\"10\" />";
$update = $Image_folder2;
$bewerk_datum2 = $Mother_Row['DOU'];
$aantal_dagen2 = floor(abs((strtotime($bewerk_datum2)-time())/(60*60*24)));
print "<span class=\"style2\">".$Mother_Row['Ch']."</span>\n";
print "</a> ";
print "<span class=\"style3\">".$Mother_Row['DogName']."</span>";
print "</a> ";
print "<span class=\"style4\">(".$Mother_Row['Color'].")</span>";
print "</a> ";
print "<span class=\"style4\">".$DOB."</span>";
print "</a>   ";
if($aantal_dagen <60){echo $new;}
else{echo'';}
if($aantal_dagen2 <60){echo $update;}
else{echo'';}
print "<br><font color='black' size='1' face='Arial'>";
print "  [<a href=\"pedigree.php?Id=$Id\">Pedigree]</a> ";
print "[<a href=\"breeding.php?Id=$Id\">Breeding]</a> ";
print "[<a href=\"sibling.php?Id=$Id\">Sibling]</a></font>";
}
print "<table width=\"80%\" height=\"40\" border=\"1\" bgcolor=\"#FFFF00\">";
print "<tr>";
print "<td valign=\"top\">";
echo Print_Single($SQL_single_Row);
print "</td></tr>";
print "</table>";
print "<table width=\"80%\" border=\"1\" bgcolor=\"#00FFFF\">";
print "<tr>";
print "<td width=\"20%\"><div align=\"center\"><strong>Sire</strong></div></td>";
print "<td width=\"87%\"><div align=\"left\">";
echo Print_Father($SQL_father_Row);
print "</div></td></tr>";
print "</table>";
print "<table width=\"80%\" border=\"1\" bgcolor=\"#FFCCCC\">";
print "<tr>";
print "<td width=\"20%\"><div align=\"center\"><strong>Dame</strong></div></td>";
print "<td width=\"87%\"><div align=\"left\">";
echo Print_Mother($SQL_mother_Row);
print "</div></td></tr>";
print "</table>";
print "<table width=\"80%\" border=\"1\" bgcolor=\"#CCCCCC\">";
print "<tr>";
print "<td width=\"20%\"><div align=\"Top\"><strong>Full Siblings - same father/mother</strong></div></td>";
print "<td width=\"87%\"><div align=\"left\">";
if (mysql_num_rows($SQL_full_Sibling_Result) >0){
$a = 1;
while($SQL_full_Sibling_Row = mysql_fetch_array( $SQL_full_Sibling_Result)) {
print "  $a";
print "  ";
echo Print_full_Sibling($SQL_full_Sibling_Row);
print "<br>";
$a++;
}
print "</div></td></tr>";
print "</table>";
}
?>