Travelling up the TAXA tree, child to parent

Bill Mudry <[email protected]>
Newsgroups gmane.comp.php.windows
Message-ID <[email protected]>
When I started my TAXA botanical tree, you could only enter at the 
top level (the Order level)
and then for some time now there are four entry points, one for each 
level. The whole tree is
based on many to one relationships:
         Order (top level) ----> Family -----> Genus (Genera) ------> 
Species(bottom of tree)
So far, you can enter (as planned) to travel down the rest of this data tree.
Now I want to finally make it possible to travel the other direction 
up the tree, from child taxon
to parent. Once I have the code that works for Family to Order 
travel, I should find it easy to
make adjustments to also create the Genus to Family and species to 
Genus links.

Once I am getting the parent order name to show up, I can also 
benefit in putting that as a subtitle.
Example:        Title:          Woody Family Buxaceae
                 Subtitle:                    Parent Order: Buxales

(Just in case anyone wishes to see this all in the site, it is still 
at www.prowebcanada.com/taxa)

By hard coding what the order name is temporarily, I was able to 
prove that the link does work and brings up the data display page for 
that order. The problem seems to be in getting the
parent name in. I figure I may need a join on the sci_order and 
sci_family tables. I am still rather slow at
working with joins yet, hoping someone would not mind speeding up 
this phase for me. Here are some key
other data names you may need:

The database is called 'taxa'

All order data is in the table sci_order
         The index is 'orderID'
         Order names are in column 'order_name' and is used to jump 
to a specific order data page.

All Family data is in the table sci_family
         The index in this table is 'familyID'
         'order_name' is also in sci_family as a foreign key. No 
constraints are added.
         Family names are in  'family_name'

Individual orders are listed using showorder.php (with woody families 
under a chosen order
showing in the second half of the page, linked to bring up a user 
chosen family page).
Individual families (user chosen) are shown using showfamilies.php.

Of course there are other columns in both tables but I am hedging a 
guess that you will not need them.
Ask for more details if you really think the other columns are really 
needed. I will include some of the
code I have so far in for this in sci_families.php. I am the first to 
say it will seem a bit messy since I was
fishing around a lot to figure this out. It can be cleaned out after 
this works).

<code>

   <?php

//////////////////////////////////////////////////////////////////////////////////////
//  File: showfamilies.php
//  Date last revision:
//  Description: Displays a family chosen by a user from a full list 
of families.
//      Called by: Alphafamilies.php
//
//
//////////////////////////////////////////////////////////////////////////////////////

////////////////////////////////
// Connect to the database first
////////////////////////////////
include ("connecttotaxa.php");
$connection = mysql_connect($hostname, $username, $password)
         or die("Unable to connect to database server");

$db = mysql_select_db($dbname, $connection)
         or die("Unable to connect to database");
////////////////////////////////
// Hopefully connected
////////////////////////////////



$order_name = $_Get['order_name'];
Echo "At line 21 \$order_name is - $order_name<br>\n"; //Nope! doesn't work!
$family_name = $_GET['family_name']; // But this works.


//parse_str($_SERVER['QUERY_STRING'], $qs);
  //$family_name=$qs['family_name'];      // Alternate method.

//Echo "\$family_name is - $family_name<br>\n";
Echo "At line 29 \$order_name is - $order_name<br>\n";


$query = "SELECT * FROM sci_family WHERE family_name='$family_name' 
order by family_name";

//var_dump($query);
$result = mysql_query($query)
         or die(mysql_error());
         //Echo "\$result is - $result <br>";
         //Echo "\$family_name is - $family_name <br>";

         Echo "<html>";
         Echo "<head>";
         Echo "<title>Information on a chosen botanical family $family_name" ;
         Echo "</title>";
/////////////////////////////////////////////////////////////////////////////////////// 

// ------------------------------ START OF BODY SECTION 
-------------------------------
///////////////////////////////////////////////////////////////////////////////////////
         echo "<body bgcolor='ivory' border='1'>";

/////////////////////////////////////////////////////////////////////////////////////// 

// --------------------- CODE TO ALLOW UPWARD TRAVEL TO PARENT ORDER 
------------------
///////////////////////////////////////////////////////////////////////////////////////

         $query = "SELECT 'sci_order.order_name'
                 FROM sci_order, sci_family
                 WHERE 'sci_order.order_id' = 'sci_family.order_id' ";
         $parent1 = $_GET[ sci_order.order_name];
//      echo "At line 56 \$parent1 is - $parent1<br />\n";
         //$parent1 = 'Arales';  // (This is what I used to 
temporarily hard code and prove this works).

/*      echo "<a href='showorder.php?&order_name=$parent1'>
         Go to the parent order<br>and families under it
         </a><br>\n";
*/

</code>
(rest of page code not related and omitted).

As always, I appreciate any help any of you can supply. I have a 
feeling this actually should be a
relatively common scenario to code. Once I get this working, it will 
transform the project from a one
way data 'street' to a two way data stream.

Bill Mudry
Mississauga, Ontario Canada
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.