This topic is locked

Dog Pedigree

7/16/2007 3:49:40 PM
PHPRunner General questions
author

Greetings:
I am trying to format my 'view' page like a pedigree but have not been able to accomplish anything that works!
Here is a link: You can log on as 'guest' to look at the format we want.

Labrador database
Click to view one of the records - find the most complete one -Alleganies Eclipse would be a good one.
The dog's name and some information is at the top.
The first column is completed by taking information from the pedigree [the dog's sire and the dog's dam].
The next column is where my problem starts - for the SIRE's sire [ie this dog's granddaddy] and Dam [ie this dog's grandmother] and the DAM's sire [ie the other granddaddy for this dog] and Dam [ie the other grandmother for this dog].
Each record in the data base contains a column for RegNames' along with the 'Sire', 'Dam', etc.
Each sire and dam's name is also listed under the 'RegName' column.
So what I need to do is after the first column [the parents] are filled in, they need to be 'this dog' so a search can be done to find their names in the 'RegName' column and get their sire and dam.
It's not nearly as complicated as it sounds and I would probably just need one script,
Also, I don't know perl but I have some scripting from a simlar project [ie creating a pedigree from a database] that I can share.
Thanks!!
Mary

Western Washington State

J
Jane 7/17/2007

Mary,
I think you can create table with all grandDads and grandMothers using ViewOnLoad event on the Events tab.

Publish your project to the Demo Account, post link to your pages here and I'll try to help you.

501288 7/18/2007

Hi Jane: just wanted you to know that I am trying to upload to demo but having problems. I hope it will be there soon. Thanks so much!

501289 7/19/2007

Mary,

I think you can create table with all grandDads and grandMothers using ViewOnLoad event on the Events tab.

Publish your project to the Demo Account, post link to your pages here and I'll try to help you.

501290 7/19/2007

Mary,

I think you can create table with all grandDads and grandMothers using ViewOnLoad event on the Events tab.

Publish your project to the Demo Account, post link to your pages here and I'll try to help you.


Hi Jane: is this what you need?
http://demo.asprunner.net/brookhill_hughes.../labs/login.php
Thanks!!!

501291 7/23/2007




Hi Jane: I belong to a forum that is run by a gentleman that writes books for php and mysql. This is the recommendation given by one of the other members with a note from the author of books that it is exactly what he would do:
>>>>>>>>

$sql = "SELECT RegName, SireID, DamID FROM pedigrees WHERE ID=$ID";

$result = mysql_query ($sql);
if ($result) {
// start an html table

echo "<table>";
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {

$dog = array ('RegName'=>$row['RegName'], 'SireID'=>$row['SireID'], 'DAM'=>$row['DamID']);
// get Sire info

$SireQ = "SELECT RegName, SireID, DamID FROM pedigrees WHERE ID={$row['SireID']}";

$SireR = mysql_query ($SireQ);
if ($SireR) {

$SireRow = mysql_fetch_array ($SireR, MYSQL_ASSOC);

$dog['Sire'] = $SireRow['RegName'];

$dog['GrandSireID'] = $SireRow['SireID'];

$dog['GrandDamID'] = $SireRow['DamID'];
// add additional queries for greatGrandSire and greatGrandDam
} else {

$dog['Sire'] = '';

$dog['GrandSireID'] = NULL;

$dog['GrandDamID'] = NULL;

} // end of $SireR conditional
// add additional queries for Dam sIDe of family (no pun intended)
// print row of results

echo "<tr><td>{$dog['RegName']}<table><tr><td>{$dog['Sire']}</td><td>{$dog['DAM']}</td></tr></table></td></tr>";
} // end of while
// close table

echo "</table>";
} // end of $result conditionalThis way, all of the dogs can be stored in one table, whether they are parents, grandparents or great-grandparents. Each will have (if you have the information) fields indicating which record in the table is related as a sire or dam. Since you are retrieving the same info whether they are a child, parent, grandparent, etc and only the WHERE clause is different, you could store the SELECT and FROM part of the query as a string, and concatenate the WHERE part at each step, to simplify it.

<<<<<<<<<<<<<<<<

Would you make it part of the 'view.htm' or the 'view.php' file?
Would you use 'Smarty' to generate the arrays? It is my understanding that he is suggesting multidimensional arrays.
Thanks!!

501292 7/23/2007



Hi Jane: I belong to a forum that is run by a gentleman that writes books for php and mysql. This is the recommendation given by one of the other members with a note from the author of books that it is exactly what he would do:
>>>>>>>>

$sql = "SELECT RegName, SireID, DamID FROM pedigrees WHERE ID=$ID";

$result = mysql_query ($sql);
if ($result) {
// start an html table

echo "<table>";
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {

$dog = array ('RegName'=>$row['RegName'], 'SireID'=>$row['SireID'], 'DAM'=>$row['DamID']);
// get Sire info

$SireQ = "SELECT RegName, SireID, DamID FROM pedigrees WHERE ID={$row['SireID']}";

$SireR = mysql_query ($SireQ);
if ($SireR) {

$SireRow = mysql_fetch_array ($SireR, MYSQL_ASSOC);

$dog['Sire'] = $SireRow['RegName'];

$dog['GrandSireID'] = $SireRow['SireID'];

$dog['GrandDamID'] = $SireRow['DamID'];
// add additional queries for greatGrandSire and greatGrandDam
} else {

$dog['Sire'] = '';

$dog['GrandSireID'] = NULL;

$dog['GrandDamID'] = NULL;

} // end of $SireR conditional
// add additional queries for Dam sIDe of family (no pun intended)
// print row of results

echo "<tr><td>{$dog['RegName']}<table><tr><td>{$dog['Sire']}</td><td>{$dog['DAM']}</td></tr></table></td></tr>";
} // end of while
// close table

echo "</table>";
} // end of $result conditionalThis way, all of the dogs can be stored in one table, whether they are parents, grandparents or great-grandparents. Each will have (if you have the information) fields indicating which record in the table is related as a sire or dam. Since you are retrieving the same info whether they are a child, parent, grandparent, etc and only the WHERE clause is different, you could store the SELECT and FROM part of the query as a string, and concatenate the WHERE part at each step, to simplify it.

<<<<<<<<<<<<<<<<

Would you make it part of the 'view.htm' or the 'view.php' file?
Would you use 'Smarty' to generate the arrays? It is my understanding that he is suggesting multidimensional arrays.
Thanks!!


Hi Again! I meant to start this email with "do you think something like this would work?
If not, just ignore all my questions!!!! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=19805&image=1&table=forumreplies' class='bbcemoticon' alt='<<' />

J
Jane 7/24/2007

Mary,
I recommend you use this code in the View Page: BeforeDisplay event on the Events tab. All values from the view page are stored on the $values array:

global $conn;

$sql = "SELECT RegName, SireID, DamID FROM pedigrees WHERE ID=".$values["ID"];

$result = db_query($sql,$conn);
if ($result) {

...

501293 7/26/2007

Mary,

I recommend you use this code in the View Page: BeforeDisplay event on the Events tab. All values from the view page are stored on the $values array:


Jane: thanks so much!!
I will give it a try!!

501294 7/26/2007



Jane: thanks so much!!
I will give it a try!!
Hi Jane: OK I tried it and I am getting this error message:
Parse error: parse error, unexpected '=', expecting ')' in /homepages/33/d208885282/htdocs/labradors/labradors/include/Pedigrees_events.php on line 147
This is the section that I believe it pertains to [line 147 on the file called Pedigreeevents.php in the 'include' directory] The second line, which I underlined, is line 147.
$dog = array (

'RegName'= $row['RegName'],_

'Sire'= $row['Sire'],

'DAM'= $row['DAM']); {

// get Sire info
I did make one change - I went back from SireID and DamID to Sire and DAM. Could that affect it?
http://demo.asprunner.net/brookhill_hughes...adors/login.php
Thanks so much for your help!!!

501295 7/27/2007





Hi Jane: I have been working on this and now it is to the point tht the view page actually opens and shows a table that I put on the bottom of it. Does this mean it's working and now I just have to get it to print properly into my table?
You can look at it here - www.fortheloveoflabradors.com/labradors/login.php by signing in as 'guest'.
If you have any ideas on getting it to print out, I sure would appreciate it. It's hard for me to figure out because if something doesn't work, I don't know if I make a typo or if the function isn't working. Thanks!!!!!!!

J
Jane 7/31/2007

Mary,
I can't test your application because there is an error in your event.

Publish your project on the Demo Account and send URL to your pages to [email=support@xlinesoft.com]support@xlinesoft.com[/email]. I'll try to help you.

501296 8/1/2007

Mary,

I can't test your application because there is an error in your event.

Publish your project on the Demo Account and send URL to your pages to [email=support@xlinesoft.com]support@xlinesoft.com[/email]. I'll try to help you.



Thanks Jane: I keep working on it but everytime I find and fix one problem, there's something else.

D
daviesgh 8/2/2007

Mary,
You may find it easier to change your database structure, and have a dog table and a parent/litter table:
Dog Table

Fields: ID, RegName, RegNo, RegCountry, Gender, Title, Addl_Titles, Color, Owner, ParentID
Parent/Litter Table

Fields: ParentID, DamID, SireID, DOB, Breeder
DamID and SireID link back the ID in the Dog Table

ParentID in the Dog Table link to ParentID in the Parent Table
This has the following advantages:

  • Information about the dog is only stored in one place - easier for searching on dog name etc
  • If you are storing dog litters on your database, it makes it easier to link them together, and you only need to store the Dam and Sire once
  • You are not limited by how many generations of dog you can store on your database
    Regards,
    Gordon

501297 8/2/2007

Mary,

You may find it easier to change your database structure, and have a dog table and a parent/litter table:
Dog Table

Fields: ID, RegName, RegNo, RegCountry, Gender, Title, Addl_Titles, Color, Owner, ParentID
Parent/Litter Table

Fields: ParentID, DamID, SireID, DOB, Breeder
DamID and SireID link back the ID in the Dog Table

ParentID in the Dog Table link to ParentID in the Parent Table
This has the following advantages:

  • Information about the dog is only stored in one place - easier for searching on dog name etc
  • If you are storing dog litters on your database, it makes it easier to link them together, and you only need to store the Dam and Sire once
  • You are not limited by how many generations of dog you can store on your database
    Regards,
    Gordon



Thanks Gordon: I actually already have sire and dam tables. Do you have suggestions as to how to handle this with them?
Jane is I think working on it. Jane, what do you think?

J
Jane 8/3/2007

Mary,
I think you can use your database structure or change it, but the code in the View page: Before process will be the similar.

You need to select all parents for the dog, place these values to the table and print this table on the view page.

501298 8/5/2007

Mary,

I think you can use your database structure or change it, but the code in the View page: Before process will be the similar.

You need to select all parents for the dog, place these values to the table and print this table on the view page.



Thanks Jane: This is what we have been trying to do. The problem is that I do not know how to do it. As it is now, with the code currently uploaded to the demo site I do not appear to be getting any errors but it is not printing out the names. So, I am not sure if it is not working or just not printing out.
Right now what I would like to do verify that the code to obtain the ancestors is working and if it is not, fix it. If it is and when it is working, I need help in getting it to print out!!

501299 8/5/2007

Mary,

I think you can use your database structure or change it, but the code in the View page: Before process will be the similar.

You need to select all parents for the dog, place these values to the table and print this table on the view page.



Ignore my last message as I just saw your email. Thanks!!!

500404 8/13/2007

OMY I cannot even believe it but my pedigree works!!! It grabs the correct info and LAYS IT OUT RIGHT - which I must say was no easy task!!!
However, I do have a snag. If the sire of the current dog is unknown I get an error message that says
'undefined variable' on the internet and 'variable used before it was identified' in another progam that checks syntax. I am certain that it is from this:
else {

$RegName == 'Unknown';

}
RegName is previously defined like this
//Get Sire(

if (is_numeric($row['SireID'])) {
$SireQ = $sql . $row['SireID'];

$SireR = mysql_query ($SireQ);
$SireRow = mysql_fetch_array ($SireR, MYSQL_ASSOC);

$SireRow = array (

'RegName' => $SireRow['RegName'],

'SireID' => $SireRow['SireID'],

'DamID' => $SireRow['DamID']);
Any advice? Thanks so much!!!!!

J
Jane 8/14/2007

Mary,
try to check value before:

//Get Sire(

if (is_numeric($row['SireID']))

{

$SireQ = $sql . $row['SireID'];

$SireR = mysql_query ($SireQ);
if ($SireRow = mysql_fetch_array ($SireR, MYSQL_ASSOC))

{

$SireRow = array (

'RegName' => $SireRow['RegName'],

'SireID' => $SireRow['SireID'],

'DamID' => $SireRow['DamID']);

}

500405 8/14/2007

HURRAY!!! It works!!! I could never had done it without your help! Thanks so much to everyone who helped me get it going!!!