I’m having a problem with retrieving information from a MySQL Table with PHP.
I Have the following table in the MySQL database:
id | pigeon_sn | mother_sn | father_sn
id – represents the unique ID;
pigeon_sn – represents the pigeon ring serial number
mother_sn – represents the mother of the pigeon – ring serial number
father_sn – represents the father of the pigeon – ring serial number
I’d like to retrieve from the database the information as a pedigree like file.
This means I need to retrieve the information as follows:
I insert the serial number of the ring of a pigeon.
– it gives me the serial number of the mother and father ring.
– then, for each new serial number ( mother and father ) retrieves the father corresponding to the serial no obtained before, and the mother corresponding to the serial no before.
– the algorithm goes on for a given number of iterations ( For example 3 will retrieve 3 generations of pigeons by their mother and father serial number ).
I belive that this can be done recursively or just by an for algorithm that goes for a given number of iterations. For every pigeon ( pigeon is represented by the serial number obtained from the pigeon before ) the algorithm will create an associative array with all the information on that row table.
Thank you in advice.
Got this working up if somebody needs it:
First you get the first pigeon and their parents:
$pedigree[0] = $this->fetchRow(“pigeon_sn='{$sn}'”);
$pedigree[1][] = $this->fetchRow(“pigeon_sn='{$pedigree[0][‘SN_m’]}'”);
$pedigree[1][] = $this->fetchRow(“pigeon_sn='{$pedigree[0][‘SN_t’]}'”);
and after that you will go like this:
for the recursive funciton.