Location: PHPKode > projects > Generic Genetic Studies Database > ggsd-2.19/cgi-bin/individual_search.php
<?php

#Copyright 2008 Aaron Day-Williams <hide@address.com>
#
#This file is part of Generic Genetic Studies Database (GGSD).
#
#GGSD is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#GGSD is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with GGSD.  If not, see <http://www.gnu.org/licenses/>.


header("Content-type: text/html");
session_cache_limiter('private');
session_start();
require 'sql_lib.inc';
require 'html_lib.inc';
require 'file_system_lib.inc';

#NAME	individual_search.php

#TYPE	PHP

#USES	sql_lib(tableQuery,distinctTableQuery,tableJoin,distinctTableJoin,compoundTableQuery)
#	html_lib(printTableSelectList,printSearchPage,printIndividualCheckList,printPedigreeCheckList,
#		 printMarkerCheckList, printGeneCheckList,printPhenotypeCheckList,printGenotypeCheckList)

#PURPOSE To allow the user to search the database for individuals in the database.  The use should be able
#	to search any table in the database, one or multiple fields in that table, and receive a list of
#	individuals that meet that search criteria.  Once a list of individuals are found, the user will be
#	able to select which markers they want genotypes for and which phenotypes they want values for and download
#	that information to a file on their local hard drive.

#USAGE	individual_search.php

#PARAMETERS
#	table name			table_name		 string		optional
#	field list			field_list		 checkbox list	optional
#	term				term			 string		optional
#	mode				mode			 string		optional
#	pedigree ids			ped_ids			 checkbox list	optional
#	gene ids			gene_ids		 checkbox list	optional
#	marker ids			marker_ids		 checkbox list	optional
#	phenotype ids			pheno_ids		 checkbox list	optional
#	individual table ids		individual_ids		 checkbox list	optional
#	genotype records		genotype_records	 checkbox list	optional
#	status				status			 string		optional
#	submit				submit			 string		optional
#	authorized user			auth_user		 int		optional
	

#RETURNS
#	error message			err_msg			string		if error
#	pedigree ids			ped_ids			checkbox list	if success
#	gene ids			gene_ids		checkbox list	if success
#	marker ids			marker_ids		checkbox list	if success
#	phenotype ids			pheno_ids		checkbox list	if success
#	individual table ids		individual_ids		checkbox list	if success
#	genotype records		genotype_records	checkbox list	if success
#	status				status			string		if success
	

#DATASTRUCTURES	There is one datastructure that needs explanation, and that is the datastructure for
#		the genotype_records variable.  The genotype_records is a string that is delimited by
#		two different delimiters.  The genotype_records holds individual information (individual_id,
#		father_id,etc.), genotype information, and phenotype information.  These three pieces of information
#		are delimited by a "/". Within each separate piece of information (e.g. individual,genotype,and phenotype)
#		the information is separated by ",".  

#FUNCTIONAL DESCRIPTION The script will first check to see if the individual accessing the script is an authorized
#		       user.  Then the script will give the user a select list of tables to search.  Then a search page
#		       for that specific table will be presented.  Then the script will display a list of checkboxes of
#		       individuals that meet the search criteria entered.  The user will select which individuals they want
#		       to see genotypes for.  The user will then select a status to investigate and the markers they want
#		       genotypes for.  The user will be given the choice of seeing genotypes or selecting phenotypes as well.
#		       Then all the data will be presented to the user.  They will select what data they would like to download,
#		       then the script will call the download script to output the data to a file on the users hard drive.

#ASSUMPTIONS That the ultimate goal of searching for individuals is to download genotpes and possibly phenotypes for the
#	    individuals found.

#LIMITATIONS

#COMMENTS

#PRELIMINARY DESIGN
#	    1	Get and Validate Args
#	    2	Validate User
#	    3	Print Table Select List
#	    4	Print Search Page
#	    5	Exectue Query and print Individual Check List
#	    6	Select Status and Markers to Investigate
#	    7	Select Phenotypes to Investigate
#	    8	Get Genotypes and Phenotypes and print Genotype Check List
#	    9	Call download.php to print selected genotypes to user's hard drive

echo "<html>\n";
echo " <head>\n";
if (isset($_POST['end_session'])){echo "  <META HTTP-EQUIV=Refresh CONTENT=\"$logout_refresh_time;URL=../right.html\">\n";}
else                             {echo "  <META HTTP-EQUIV=Refresh CONTENT=\"$normal_refresh_time; URL=$_SERVER[SCRIPT_NAME]\">\n";}
echo "  <title>Individual Search</title>\n";
echo " </head>\n";

echo "<body bgcolor=\"white\">\n";
echo "<center><h3>Individual Search</h3></center>\n";
echo "<hr>\n";
printHomeNavBar();
echo "<br>\n";  


	#1	Get and Validate Args
$DEBUG                 = '0';
$access_type_required  = 'search';
$table_name            = $_POST['table_name'];
$field_list            = $_POST['field_list'];
$term                  = $_POST['term'];
$mode                  = $_POST['mode'];
$join                  = $_POST['join'];
$order_by              = $_POST['order_by'];
$function_to_call      = $_POST['function_to_call'];
$last_record_retrieved = $_POST['last_record_retrieved'];
$chromosome_ids        = $_POST['chromosome_id'];
$marker_ids            = $_POST['marker_id'];
$pheno_ids             = $_POST['pheno_id'];
$individual_ids        = $_POST['indiv_id'];
$status                = $_POST['status'];
$individual_flag       = $_POST['individual_flag'];
$indiv_multiple_pages  = $_POST['indiv_multiple_pages'];
$marker_multiple_pages = $_POST['marker_multiple_pages'];
$pheno_multiple_pages  = $_POST['pheno_multiple_pages'];
$submit                = $_POST['submit'];
$create_analysis_files = $_POST['create_analysis_files'];
$analysis_option       = $_POST['analysis_option'];
$analysis_sub_option   = $_POST['analysis_sub_option'];
$r_plot_statistics     = $_POST['r_plot_statistics'];
	
if ($DEBUG)
  {
    echo "Input parameters are:<br>\n";
    echo "table_name     = $table_name<br>\n";
    echo "field_list     = ".join($field_list,',')."<br>\n";
    echo "term           = ".join($term,',')."<br>\n";
    echo "mode           = ".join($mode,',')."<br>\n";
    echo "join           = $join<br>\n";
    echo "marker_ids     = ".join($marker_ids,',')."<br>\n";
    echo "pheno_ids      = ".join($pheno_ids,',')."<br>\n";
    echo "individual_ids = ".join($individual_ids,',')."<br>\n";
    echo "status         = $status<br>\n";
    echo "submit         = $submit<br>\n";
    echo "<br><br>\n";
  }

$ret_val = connect();
if ($ret_val != '1')
  {
    $date = date('Y-m-d H:i:s');
    echo "Error #1: $date<br>\n";
    echo "Error in call to connect from individual_search.php<br>\n";
    echo "$ret_val<br><br>\n";
    echo "Please email the above error using the Comments/Help/Support link \n";
    echo "in the left navigation bar.<br>\n";
    echo "</body></html>\n";
    exit;
  }


	#2	Validate User
if (isset($_POST['end_session']))#if want to end session
  {
    #if (key_exists('files_on_server',$_SESSION))
    #  {
    #    $files_to_delete_array = $_SESSION['files_on_server'];
    #    $ret_val = deleteFiles($files_to_delete_array);
    #    if ($ret_val != '1')
    #      {
    #        $date = date('Y-m-d H:i:s');
    #        echo "Error #2: $date<br>\n";
    #        echo "Error in call to deleteFiles from individual_search.php<br>\n";
    #        echo "$ret_val<br><br>\n";
    #        echo "Please email the above error using Comments/Help/Support link \n";
#	    echo "in the left navigation bar.<br>\n";
#	    echo "</body></html>\n";
#	    session_unset();
#	    session_destroy();
#	    $ret_val = disconnect();
#	    exit;
#	  }#end error in call to deleteFiles
#      }#end if files that need to be deleted

    if (is_dir("../data/download_data/$_SESSION[user_name]"))
      {
        $ret_val = deleteExpiredFiles($_SESSION['user_name']);
        if ($ret_val != '1')
          {
            $date = date('Y-m-d H:i:s');
            echo "Error #3: $date<br>\n";
            echo "Error in call to deleteExpiredFiles from individual_search.php<br>\n";
            echo "$ret_val<br><br>\n";
            echo "Please email the above error using Comments/Help/Support link \n";
	    echo "in the left navigation bar.<br>\n";
	    echo "</body></html>\n";
	    session_unset();
	    session_destroy();
	    $ret_val = disconnect();
	    exit;
	  }#end error in call to deleteExpiredFiles
      }#end if user has own directory in download_data directory
    session_unset();
    session_destroy();
    echo "You have successfully logged out of the system.<br>\n";
    #echo "To log back in click on any of the links on the left navigation bar.<br>\n";
    $ret_val = disconnect();
    exit;
  }#end if want to end session
else#don't want to end session
  {
    if ((!session_is_registered('user_name')) and (!session_is_registered('user_passwd')))
      {
	if ((!preg_match('/\w+/',$_POST['user_name'])) and (!preg_match('/\w+/',$_POST['user_passwd'])))
	  {
	    $ret_val = printLoginPage('individual_search.php');
            if ($ret_val != '1')
              {
                $date = date('Y-m-d H:i:s');
		echo "Error #4: $date<br>\n";
		echo "Error in call to printLoginPage from individual_search.php<br>\n";
		echo "$ret_val<br><br>\n";
		echo "Please email the above error using Comments/Help/Support link \n";
		echo "in the left navigation bar.<br>\n";
		echo "</body></html>\n";
		session_unset();
		session_destroy();
		$ret_val = disconnect();
		exit;
	      }#end if error in call to printLoginPage
	  }#end if haven't started a session yet
        else #have started a session
	  {
	    $auth_user = authenticate($_POST['user_name'],$_POST['user_passwd'],$_POST['rand'],$access_type_required,$_POST['database_id']);
	    if (($auth_user != '1') and ($auth_user != '0'))
	      {
		$date = date('Y-m-d H:i:s');
		echo "Error #5: $date<br>\n";
		echo "Error in call to authenticate from individual_search.php<br>\n";
		echo "$auth_user<br>\n";
		echo "Please email the above error using Comments/Help/Support link \n";
		echo "in the left navigation bar.<br>\n";
		echo "</body></html>\n";
		session_unset();
		session_destroy();
		$ret_val = disconnect();
		exit;
	      }
            if ($auth_user == '0')
	      {
		echo "You are not an authorized user of this website!!<br><br>\n";
		echo "You must be an authorized user to access the data contained in this site.\n";
		echo "If you feel like you should be an authorized user, or want to see if you can\n";
		echo "become an authorized user please contact $contact_person at \n";
                echo "<a href=\"mailto:$contact_email\">$contact_email</a>\n";
		echo "</body></html>\n";
		session_unset();
		session_destroy();
		$ret_val = disconnect();
		exit;
	      }
            if ($auth_user == '1')
	      {
		$_SESSION['user_name']   = $_POST['user_name'];
		$_SESSION['user_passwd'] = $_POST['user_passwd'];
                $_SESSION['database_id'] = $_POST['database_id'];
		$_SESSION['rand']        = $_POST['rand'];
                $_SESSION['entry_time']  = time();
		session_write_close();
	      }
	  }#end else have user name an passwd
      }#end if session variables not registered
    else #session variable are registered
      {
        if ((time() - $_SESSION['entry_time']) > $session_expiration_time)#if session has expired
          {
            #if (key_exists('files_on_server',$_SESSION))
            #  {
            #    $files_to_delete_array = $_SESSION['files_on_server'];
            #    $ret_val = deleteFiles($files_to_delete_array);
            #    if ($ret_val != 1)
            #      {
            #        $date = date('Y-m-d H:i:s');
            #        echo "Error #6: $date<br>\n";
            #        echo "Error in call to deleteFiles from individual_search.php<br>\n";
            #        echo "$ret_val<br><br>\n";
            #        echo "Please email the above error using Comments/Help/Support link \n";
	#	    echo "in the left navigation bar.<br>\n";
        #            session_unset();
        #            session_destroy();
        #            $ret_val = disconnect();
        #            exit;
        #          }#end if error in call to deleteFiles
        #      }#end if files that need to be deleted

            if (is_dir("../data/download_data/$_SESSION[user_name]"))
              {
                $ret_val = deleteExpiredFiles($_SESSION['user_name']);
                if ($ret_val != 1)
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "Error #7: $date<br>\n";
                    echo "Error in call to deleteExpiredFiles from individual_search.php<br>\n";
                    echo "$ret_val<br><br>\n";
                    echo "Please email the above error using Comments/Help/Support link \n";
		    echo "in the left navigation bar.<br>\n";
                    session_unset();
                    session_destroy();
                    $ret_val = disconnect();
                    exit;
                  }#end if error in call to deleteExpiredFiles
              }#end if user has a data directory
            session_unset();
            session_destroy();

            echo "<b>Your Session has expired.  You must log back into the system.</b><br><br><br>\n";
            $ret_val = printLoginPage('individual_search.php');
            if ($ret_val != '1')
              {
                $date = date('Y-m-d H:i:s');
		echo "Error #8: $date<br>\n";
		echo "Error in call to printLoginPage from individual_search.php<br>\n";
		echo "$ret_val<br><br>\n";
		echo "Please email the above error using Comments/Help/Support link \n";
		echo "in the left navigation bar.<br>\n";
		echo "</body></html>\n";
		session_unset();
		session_destroy();
		$ret_val = disconnect();
		exit;
	      }#end if error in call to printLoginPage
          }#end if session has expired 
        else #session hasn't expired
          {
	    if ((!session_is_registered('database_id')) and (!isset($_POST['database_id'])))
	      {
		$ret_val = printDatabaseSelectPage('individual_search.php');
		if ($ret_val != '1')
		  {
		    $date = date('Y-m-d H:i:s');
		    echo "Error #9: $date<br>\n";
		    echo "Error in call to printDatabaseSelectPage from individual_search.php<br>\n";
		    echo "$ret_val<br><br>\n";
		    echo "Please email the above error using Comments/Help/Support link \n";
		    echo "in the left navigation bar.<br>\n";
		    echo "</body></html>\n";
		    session_unset();
		    session_destroy();
		    $ret_val = disconnect();
		    exit;
		  }#end if error in call to printDatabaseSelectPage
	      }#end if the database id session variable isn't set and haven't selected
	    else #all the session variables are set
	      {
		$user_name   = $_SESSION['user_name'];
		$user_passwd = $_SESSION['user_passwd'];
		if (session_is_registered('database_id')){$database_id = $_SESSION['database_id'];}
		else #set database id session variable
		  {
		    $database_id = $_POST['database_id']; 
		    $_SESSION['database_id'] = $_POST['database_id'];
		  }#end else set database id session variable
		$rand        = $_SESSION['rand'];
		$_SESSION['entry_time'] = time();
		$auth_user = authenticate($user_name,$user_passwd,$rand,$access_type_required,$database_id);
		if (($auth_user != '1') and ($auth_user != '0'))
		  {
		    $date = date('Y-m-d H:i:s');
		    echo "Error #10: $date<br>\n";
		    echo "Error in call to authenticate from individual_search.php<br>\n";
		    echo "$auth_user<br>\n";
		    echo "Please email the above error using Comments/Help/Support link \n";
		    echo "in the left navigation bar.<br>\n";
		    echo "</body></html>\n";
		    session_unset();
		    session_destroy();
		    $ret_val = disconnect();
		    exit;
		  }
		if ($auth_user == '0')
		  {
		    echo "You are not an authorized user of this website!!<br><br>\n";
		    echo "You must be an authorized user to access the data contained in this site.\n";
		    echo "If you feel like you should be an authorized user, or want to see if you can\n";
		    echo "become an authorized user please contact $contact_person \n";
		    echo "at <a href=\"mailto:$contact_email\">$contact_email</a>\n";
		    echo "</body></html>\n";
		    session_unset();
		    session_destroy();
		    $ret_val = disconnect();
		    exit;
		  }
	      }#end else all the session variables are set
          }#end else session hasn't expired
      }#end else registered values
  }#end else not ending session

	if ($auth_user == '1')
          {
	    $database_id = $_SESSION['database_id'];
	   if ($individual_flag != '1')
             {
	      #3  Print Table Select List
	      if ((!preg_match('/\w+/',$table_name)) and
		  (sizeof($field_list) == '0') and
		  (sizeof($term) == '0') and
		  (sizeof($mode) == '0') and
                  (!preg_match('/\w+/',$join))
		 )
                {
		 echo "This form will allow you to search for individuals in the database based upon \n";
		 echo "search criteria from any of the tables in the database.  You will first need to \n";
		 echo "select the table from which the search criteria will be used to find individuals.  \n";
		 echo "Second you will need to select which fields in that table to search, the term you want \n";
		 echo "to search for, and the type or mode of search to conduct.  You will then be presented with \n";
		 echo "a list of individuals that meet your search criteria.  You can then select any or all of the \n";
		 echo "individuals to see genotype and phenotype information on.  You will then be asked to select which status \n";
		 echo "to investigate, which markers you want genotypes for, and whether you want to invesitgate any phenotypes.  \n";
		 echo "If you want to investigate phenotypes you will be able to select which phenotypes.  You will then be presented \n";
		 echo "with a list of genotypes and phenotypes for the individuals you selected.  You will then be able to download that \n";
		 echo "data to you computer.<br><br>\n";
		 echo "<form action=\"individual_search.php\" name=\"form\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(this))\">\n";
		 echo "<center>\n";
                 echo "Please select a Table to Search:<br><br>\n";
		 $jscript = printTableSelectList();
		 if ($jscript == '0')
                   {
                    $date = date('Y-m-d H:i:s');
		    echo "Error #11: $date<br>\n";
		    echo "Error in call to printTableSelectList from individual_search.php<br>\n";
		    echo "See above error message from printTableSelectList for an explanation<br><br>\n";
		    echo "Please email the above error using the Comments/Help/Support link on \n";
		    echo "the left navigation bar.\n";
		    echo "</form>\n";
		    echo "</body></html>\n";
		    $ret_val = disconnect();
		    exit;
		   }#end if (jscript == '0')
                 echo "<br>\n";
                 echo "<input type=\"submit\" name=\"submit\" value=\"Search for Individuals\">\n";
		 echo "<input type=\"reset\" name=\"reset\" value=\"Reset Values\">\n";
                 echo "</form>\n";
                 echo "</center>\n";
                 echo "<br><br>\n";

                 $ret_val = printLogOutButton('individual_search.php');
		 echo "\n\n";

		 echo "<script>\n";
		 echo "function Validate(form)\n";
		 echo "$jscript\n";
		 echo "</script>\n";
	        }#end if no table_name,field_list,mode,term

	      #4	  Print Search Page
	      if ((preg_match('/\w+/',$table_name)) and
		  (sizeof($field_list) == '0') and
		  (sizeof($term) == '0') and
		  (sizeof($mode) == '0') and
                  (!preg_match('/\w+/',$join))
		 )
                {
		 echo "<form action=\"individual_search.php\" name=\"form\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(this))\">\n";
                 #echo "Please select which Fields to search, enter the search term for those fields, and select how to join those terms:<br><br>\n";
		 echo "Please select the criteria you want Individuals to meet:<br><br>\n";
                 echo "(1) Select which field(s) to search<br>\n";
                 echo "(2) Enter the term(s) to search the field(s) with<br>\n";
                 echo "(3) If multiple fields were selected, select how to join the search criteria<br><br>\n";
		 $jscript = printSearchPage($table_name,$database_id);
		 if ($jscript == '0')
                   {
                    $date = date('Y-m-d H:i:s');
		    echo "Error #12: $date<br>\n";
		    echo "Error in call to printSearchPage from individual_search.php<br>\n";
		    echo "See above error message from printSearchPage for an explanation<br><br>\n";
		    echo "Please email the above error using the Comments/Help/Support link on \n";
		    echo "the left navigation bar.\n";
		    echo "</form>\n";
		    echo "</body></html>\n";
		    $ret_val = disconnect();
		    exit;
		   }#end if (jscript == '0')
		 echo "<center>\n";
		 echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
		 echo "<input type=\"submit\" name=\"submit\" value=\"Search for Individuals\">\n";
		 echo "<input type=\"reset\" name=\"reset\" value=\"Reset Values\">\n";
                 echo "</form>\n";
                 echo "</center>\n";
                 echo "<br><br>\n";

                 $ret_val = printLogOutButton('individual_search.php');
		 echo "\n\n";

		 echo "<script>\n";
		 echo "function Validate(form)\n";
		 echo "$jscript\n";
		 echo "</script>\n";
	        }#end if have table_name, but no field_list,term,mode

	      #5	  Execute Query and print Individual Check List
	      if ((preg_match('/\w+/',$table_name)) and
		  (sizeof($field_list) > '0') and
		  (sizeof($term) > '0') and
		  (sizeof($mode) > '0') and
                  (preg_match('/\w+/',$join))
		 )
                {
                 echo "Select which Individuals you want data for:<br><br>\n";

                 if ($table_name == 'individual_table')
                   {
                    if (sizeof($field_list) == '1')
                      {
                        $num_of_modes = sizeof($mode);
                        for ($i = '0'; $i < $num_of_modes; $i++)
                          {
                            if ($mode[$i] != 'Select Type of Search')
                              {
                                $search_term = $term[$i];
                                $search_mode = $mode[$i];
                              }
                          }#end determine which term and mode to use

			if (preg_match('/_affection_status/',$field_list[0]))
			  {
			    preg_match('/(.+)_affection_status/',$field_list[0],$captured);
                            $affection_name = $captured[1];
                            $affect_field_list = array('affection_status_name');
                            $affect_rec_list = tableQuery('affection_status_table',$database_id,$affect_field_list,$affection_name,'equal','all');
                            if (!is_array($affect_rec_list))
                              {
				$date = date('Y-m-d H:i:s');
				echo "Error #13: $date<br>\n";
				echo "Error in call to tableQuery from individual_search.php<br>\n";
				echo "$affect_rec_list<br><br>\n";
				echo "Please email the above error using the Comments/Help/Support link on the \n";
				echo "left navigation bar.\n";
				echo "</form>\n";
				echo "</body></html>\n";
				$ret_val = disconnect();
				exit;
			      }#end error in call to tableQuery
			    if (sizeof($affect_rec_list) == '0')
			      {
				$date = date('Y-m-d H:i:s');
				echo "There is no affection status in the database with name $affection_name.  \n";
                                echo "It appears that it was deleted from the database before you submitted your request \n";
				echo "to search for individuals based upon its value.  \n";
                                echo "This message was generated at $date.\n";
                                echo "</form>\n";
                                echo "</body></html>\n";
                                $ret_val = disconnect();
                                exit;
			      }#end no records
			    elseif (sizeof($affect_rec_list) == '1') {$affect_rec = $affect_rec_list[0];}
			    else
			      {
				$date = date('Y-m-d H:i:s');
				echo "Error #14: $date<br>\n";
				echo "User wanted to search based upon affection status $affection_name, but \n";
				echo "when queried the affection status table with that name multiple records were returned.<br><br>\n";
				echo "Please email the above error using the Comments/Help/Support link on the \n";
				echo "left navigation bar.\n";
				echo "</form>\n";
				echo "</body></html>\n";
				$ret_val = disconnect();
				exit;
			      }#end error in data integrity
			    unset($affect_rec_list);

			    $field_list = array('affection_status_id','individual_affection_status');
			    $term_array = array($affect_rec['affection_status_id'],$search_term);
			    $mode_array = array('equal',$search_term);
			    $indiv_table_id_array = distinctCompoundTableQuery('individual_table_id','individual_affection_status_link_table',$database_id,$field_list,$term_array,$mode_array,'and','all');
			    if (!is_array($indiv_table_id_array))
			      {
				$date = date('Y-m-d H:i:s');
				echo "Error #15: $date<br>\n";
				echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
				echo "$indiv_table_id_array<br><br>\n";
				echo "Please email the above error using the Comments/Help/Support link on the \n";
				echo "left navigation bar.\n";
				echo "</form>\n";
				echo "</body></html>\n";
				$ret_val = disconnect();
				exit;
			      }#end error in call to distinctCompoundTableQuery
			    if (sizeof($indiv_table_id_array) == '0')
			      {
				echo "<center>\n";
				echo "Your search of the Individual Table did not yield any individuals.<br>\n";
				echo "Please try your search again with different search criteria.<br>\n";
				echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
				echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
				echo "</center>\n";
				echo "</form>\n";
				echo "</body></html>\n";
				$ret_val = disconnect();
				exit;
			      }#end if (sizeof(indiv_table_id_array) == '0')
			    $indiv_table_id_term = join($indiv_table_id_array);
                            unset($indiv_table_id_array);
                            unset($affect_rec);

			    $field_list = array('individual_table_id');
                            $num_of_indivs = countTableQuery($table_name,$database_id,$field_list,$indiv_table_id_term,'in');
                            if (!preg_match('/^\d+$/',$num_of_indivs))
                              {
                                $date = date('Y-m-d H:i:s');
                                echo "Error #16: $date<br>\n";
				echo "Error in call to countTableQuery from individual_search.php<br>\n";
				echo "$num_of_indivs<br><br>\n";
				echo "Please email the above error using the Comments/Help/Support link on the \n";
				echo "left navigation bar.\n";
				echo "</form>\n";
				echo "</body></html>\n";
				$ret_val = disconnect();
				exit;
			      }#end error in call to countTableQuery
                            #echo "Your search of the $table_aliases[$table_name] table returned $num_of_indivs individual records.<br><br>\n";

			    #if ($num_of_indivs > $max_records_to_print)
                            #  {
                            #    echo "Your search returned $num_of_indivs individuals.<br>\n";
                            #    tooManyIndividuals($indiv_table_id_term);
                            #    $ret_val = disconnect();
                            #    exit;
                            #  }#end if more than max

			    if ($num_of_indivs > ($max_records_to_print_per_page * 5))
                              {
                                if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                                if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                                $indiv_table_id_array = distinctTableQuery('individual_table_id','individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in','all',$order_by);
                                if (!is_array($indiv_table_id_array))
                                  {
                                    $date = date('Y-m-d H:i:s');
			            echo "Error #17: $date<br>\n";
			            echo "Error in call to distincTableQuery from individual_search.php<br>\n";
			            echo "$indiv_table_id_array<br><br>\n";
			            echo "Please email the above error using the Comments/Help/Support link on the \n";
			            echo "left navigation bar.\n";
			            echo "</form>\n";
			            echo "</body></html>\n";
			            $ret_val = disconnect();
			            exit;
			          }#end if error call to distinctTableQuery
                                $all_indiv_table_id_term = join($indiv_table_id_array,',');
                                unset($indiv_table_id_array);
                                
                                moreThanFivePages($all_indiv_table_id_term);
                                unset($all_indiv_table_id_term);
                              }#end if more than 5 pages

			    if ($num_of_indivs > $max_records_to_print_per_page)
			      {
				$indiv_multiple_pages = 1;
                                $from                 = "0";
                                $to                   = $max_records_to_print_per_page - 1;
                                $range                = "$from"."-"."$to";
                                if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                                if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
			        $indiv_rec_list = tableQuery($table_name,$database_id,$field_list,$indiv_table_id_term,'in',$range,$order_by);
			        if (!is_array($indiv_rec_list))
			          {
                                    $date = date('Y-m-d H:i:s');
				    echo "Error #18: $date<br>\n";
				    echo "Error in call to tableQuery from individual_search.php<br>\n";
				    echo "$indiv_rec_list<br><br>\n";
				    echo "Please email the above error using the Comments/Help/Support link on the \n";
				    echo "left navigation bar.\n";
				    echo "</form>\n";
				    echo "</body></html>\n";
				    $ret_val = disconnect();
				    exit;
			          }#end if (!is_array(indiv_rec_list))
		                if (sizeof($indiv_rec_list) == '0')
			          {
				    echo "<center>\n";
				    echo "Your search of the Individual Table did not yield any individuals.<br>\n";
				    echo "Please try your search again with different search criteria.<br>\n";
				    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
				    echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
				    echo "</center>\n";
				    echo "</form>\n";
				    echo "</body></html>\n";
				    $ret_val = disconnect();
				    exit;
			          }#end if (sizeof(indiv_rec_list) == '0')
				$final_function_call   = 'tableQuery';
				$final_table_name      = $table_name;
				$final_field_list      = $field_list;
				$final_term            = $indiv_table_id_term;
				$final_mode            = 'in';
				$final_order_by        = $order_by;
                                $last_record_retrieved = $max_records_to_print_per_page;
			      }#end if more than one page
			    else #only a single page
			      {
				$indiv_multiple_pages = 0;
                                $range                = "all";
                                if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                                if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
				$indiv_rec_list = tableQuery($table_name,$database_id,$field_list,$indiv_table_id_term,'in',$range,$order_by);
			        if (!is_array($indiv_rec_list))
			          {
                                    $date = date('Y-m-d H:i:s');
				    echo "Error #19: $date<br>\n";
				    echo "Error in call to tableQuery from individual_search.php<br>\n";
				    echo "$indiv_rec_list<br><br>\n";
				    echo "Please email the above error using the Comments/Help/Support link on the \n";
				    echo "left navigation bar.\n";
				    echo "</form>\n";
				    echo "</body></html>\n";
				    $ret_val = disconnect();
				    exit;
			          }#end if (!is_array(indiv_rec_list))
		                if (sizeof($indiv_rec_list) == '0')
			          {
				    echo "<center>\n";
				    echo "Your search of the Individual Table did not yield any individuals.<br>\n";
				    echo "Please try your search again with different search criteria.<br>\n";
				    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
				    echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
				    echo "</center>\n";
				    echo "</form>\n";
				    echo "</body></html>\n";
				    $ret_val = disconnect();
				    exit;
			          }#end if (sizeof(indiv_rec_list) == '0')
			      }#end else only a single page
			  }#end if affection status field
			else #individual table field
			  {
                            $num_of_indivs = countTableQuery($table_name,$database_id,$field_list,$search_term,$search_mode);
                            if (!preg_match('/^\d+$/',$num_of_indivs))
                              {
                                $date = date('Y-m-d H:i:s');
                                echo "Error #20: $date<br>\n";
				echo "Error in call to countTableQuery from individual_search.php<br>\n";
				echo "$num_of_indivs<br><br>\n";
				echo "Please email the above error using the Comments/Help/Support link on the \n";
				echo "left navigation bar.\n";
				echo "</form>\n";
				echo "</body></html>\n";
				$ret_val = disconnect();
				exit;
			      }#end error in call to countTableQuery
                            #echo "Your search of the $table_aliases[$table_name] table returned $num_of_indivs individual records.<br><br>\n";

                            #if ($num_of_indivs > $max_records_to_print)
                            #  {
                            #    if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            #    if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                            #    $indiv_table_id_array = distinctTableQuery('individual_table_id',$table_name,$database_id,$field_list,$search_term,$search_mode,'all',$order_by);
			#	if (!is_array($indiv_table_id_array))
			#	  {
			#	    $date = date('Y-m-d H:i:s');
			#	    echo "Error #21: $date<br>\n";
			#	    echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
			#	    echo "$indiv_table_id_array<br><br>\n";
			#	    echo "Please email the above error using the Comments/Help/Support link on the \n";
			#	    echo "left navigation bar.\n";
			#	    echo "</form>\n";
			#	    echo "</body></html>\n";
			#	    $ret_val = disconnect();
			#	    exit;
			#	  }#end if (!is_array(indiv_rec_list))
			#	$indiv_table_id_term = join(',',$indiv_table_id_array);
                        #        echo "Your search returned $num_of_indivs individuals.<br>\n";
                        #        tooManyIndividuals($indiv_table_id_term);
                        #        $ret_val = disconnect();
                        #        exit;
                        #      }#end if more than max records to print

			    if ($num_of_indivs > ($max_records_to_print_per_page * 5))
                              {
                                if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                                if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                                $indiv_table_id_array = distinctTableQuery('individual_table_id',$table_name,$database_id,$field_list,$search_term,$search_mode,'all',$order_by);
				if (!is_array($indiv_table_id_array))
				  {
				    $date = date('Y-m-d H:i:s');
				    echo "Error #22: $date<br>\n";
				    echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
				    echo "$indiv_table_id_array<br><br>\n";
				    echo "Please email the above error using the Comments/Help/Support link on the \n";
				    echo "left navigation bar.\n";
				    echo "</form>\n";
				    echo "</body></html>\n";
				    $ret_val = disconnect();
				    exit;
				  }#end if (!is_array(indiv_rec_list))
				$all_indiv_table_id_term = join(',',$indiv_table_id_array);
                                moreThanFivePages($all_indiv_table_id_term);
                                unset($indiv_table_id_array);
                                unset($all_indiv_table_id_term);
                              }#end if more than 5 pages returned

			    if ($num_of_indivs > $max_records_to_print_per_page)
			      {
				$indiv_multiple_pages = 1;
                                $from                 = "0";
                                $to                   = $max_records_to_print_per_page - 1;
                                $range                = "$from"."-"."$to";
                                if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                                if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
				$indiv_rec_list = tableQuery($table_name,$database_id,$field_list,$search_term,$search_mode,$range,$order_by);
				if (!is_array($indiv_rec_list))
				  {
				    $date = date('Y-m-d H:i:s');
				    echo "Error #23: $date<br>\n";
				    echo "Error in call to tableQuery from individual_search.php<br>\n";
				    echo "$indiv_rec_list<br><br>\n";
				    echo "Please email the above error using the Comments/Help/Support link on the \n";
				    echo "left navigation bar.\n";
				    echo "</form>\n";
				    echo "</body></html>\n";
				    $ret_val = disconnect();
				    exit;
				  }#end if (!is_array(indiv_rec_list))
                                if (sizeof($indiv_rec_list) == '0')
			          {
				    echo "<center>\n";
				    echo "Your search of the Individual Table did not yield any individuals.<br>\n";
				    echo "Please try your search again with different search criteria.<br>\n";
				    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
				    echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
				    echo "</center>\n";
				    echo "</form>\n";
				    echo "</body></html>\n";
				    $ret_val = disconnect();
				    exit;
			          }#end if (sizeof(indiv_rec_list) == '0')
				$final_function_call   = 'tableQuery';
				$final_table_name      = $table_name;
				$final_field_list      = $field_list;
				$final_term            = $search_term;
				$final_mode            = $search_mode;
				$final_order_by        = $order_by;
                                $last_record_retrieved = $max_records_to_print_per_page;
                              }#end if multiple pages
                            else #only a single page
			      {
				$indiv_multiple_pages = 0;
                                $range                = "all";
                                if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                                if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
				$indiv_rec_list = tableQuery($table_name,$database_id,$field_list,$search_term,$search_mode,$range,$order_by);
				if (!is_array($indiv_rec_list))
				  {
				    $date = date('Y-m-d H:i:s');
				    echo "Error #24: $date<br>\n";
				    echo "Error in call to tableQuery from individual_search.php<br>\n";
				    echo "$indiv_rec_list<br><br>\n";
				    echo "Please email the above error using the Comments/Help/Support link on the \n";
				    echo "left navigation bar.\n";
				    echo "</form>\n";
				    echo "</body></html>\n";
				    $ret_val = disconnect();
				    exit;
				  }#end if (!is_array(indiv_rec_list))
			        if (sizeof($indiv_rec_list) == '0')
				  {
				    echo "<center>\n";
				    echo "Your search of the Individual Table did not yield any individuals.<br>\n";
				    echo "Please try your search again with different search criteria.<br>\n";
				    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
				    echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
				    echo "</center>\n";
				    echo "</form>\n";
				    echo "</body></html>\n";
				    $ret_val = disconnect();
				    exit;
				  }#end if (sizeof(indiv_rec_list) == '0')
			      }#end else only a single page
			  }#end else individual table field
                      }#end if sizeof(field_list) == '1'
                    else #sizeof(field_list) > '1'
                      {
			$affect_field_list = array();
			$affect_term_array = array();
			$affect_mode_array = array();
			$final_query_field_list = array();
                        $final_query_term_array = array();
                        $final_query_mode_array = array();
                        $num_of_fields = sizeof($field_list);
                        $num_of_modes  = sizeof($mode);
                        for ($i = 0; $i < $num_of_fields; $i++)
                          {
			    if (preg_match('/_affection_status/',$field_list[$i]))
			      {
				$affect_field_list[] = $field_list[$i];
				$place_on_field_list = ($i + 1);
				$num_of_mode_seen    = '0';
				for ($j='0'; $j<$num_of_modes; $j++)
				  {
				    if ($mode[$j] != 'Select Type of Search')
				      {
					$num_of_mode_seen = ($num_of_mode_seen + 1);
					if ($place_on_field_list == $num_of_mode_seen)
					  {
					    $affect_term_array[] = $term[$j];
					    $affect_mode_array[] = $mode[$j];
					  }#end if right place on list
                                      }#end if real mode
                                  }#end foreach mode
			      }#end if affection status field
			    else #individual table field
			      {
				$final_query_field_list[] = $field_list[$i];
				$place_on_field_list = ($i + 1);
				$num_of_mode_seen    = '0';
				for ($j='0'; $j<$num_of_modes; $j++)
				  {
				    if ($mode[$j] != 'Select Type of Search')
				      {
					$num_of_mode_seen = ($num_of_mode_seen + 1);
					if ($place_on_field_list == $num_of_mode_seen)
					  {
					    $final_query_term_array[] = $term[$j];
					    $final_query_mode_array[] = $mode[$j];
					  }#end if right place on list
                                      }#end if real mode
                                  }#end foreach mode
			      }#end else individual table field
                          }#end build queries

			if (sizeof($affect_field_list) > '0')
			  {
			    if (sizeof($affect_field_list) > '1')
			      {
				for ($i='0'; $i < sizeof($affect_field_list); $i++)
				  {
				    $affection_name = preg_replace('/_affection_status/','',$affect_field_list[$i]);
				    $field_list     = array('affection_status_name');
				    $affect_id_array = distinctTableQuery('affection_status_id','affection_status_table',$database_id,$field_list,$affection_name,'equal','all');
				    if (!is_array($affect_id_array))
				      {
					$date = date('Y-m-d H:i:s');
					echo "Error #25: $date<br>\n";
					echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
					echo "$affect_id_array<br><br>\n";
					echo "Please email the above error using the Comments/Help/Support link on the \n";
					echo "left navigation bar.\n";
					echo "</form>\n";
					echo "</body></html>\n";
					$ret_val = disconnect();
					exit;
				      }#end error in call to distinctTableQuery
                                    if (sizeof($affect_id_array) == '0')
				      {
					if ($join == 'and')
					  {
					    echo "<center>\n";
					    echo "Your search of the Individual Table did not yield any individuals.<br>\n";
					    echo "Please change your search criteria and try a new search.\n";
                                            echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
					    echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
					    echo "</center>\n";
					    echo "</form>\n";
					    echo "</body></html>\n";
					    $ret_val = disconnect();
					    exit;
					  }#end if join == and
				      }#end if no records
                                    else #have records
				      {
					if (sizeof($affect_id_array) == '1') {$affect_id = $affect_id_array[0];}
					else #more than 1 affect_id
					  {
					    $date = date('Y-m-d H:i:s');
					    echo "Error #26: $date<br>\n";
					    echo "User wanted to search using affection status for affection $affection_name.  \n";
					    echo "But when queried the affection status table with that name, multiple records were returned.<br><br>\n";
					    echo "Please email the above error using the Comments/Help/Support link on the \n";
					    echo "left navigation bar.\n";
					    echo "</form>\n";
					    echo "</body></html>\n";
					    $ret_val = disconnect();
					    exit;
					  }#end error in data integrity
                                       
                                        $field_list = array('affection_status_id','individual_affection_status');
					$term_array = array($affect_id,$affect_term_array[$i]);
					$mode_array = array('equal',$affect_mode_array[$i]);
					$rec_list = distinctCompoundTableQuery('individual_table_id','individual_affection_status_link_table',$database_id,$field_list,$term_array,$mode_array,'and','all');
					if (!is_array($rec_list))
					  {
					    $date = date('Y-m-d H:i:s');
					    echo "Error #27: $date<br>\n";
					    echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
					    echo "$rec_list<br><br>\n";
					    echo "Please email the above error using the Comments/Help/Support link on the \n";
					    echo "left navigation bar.\n";
					    echo "</form>\n";
					    echo "</body></html>\n";
					    $ret_val = disconnect();
					    exit;
					  }#end error in call to distinctCompoundTableQuery
					if (sizeof($rec_list) == '0')
					  {
					    if ($join == 'and')
					      {
						echo "<center>\n";
						echo "Your search of the Individual Table did not yield any individuals.<br>\n";
						echo "Please change your search criteria and try a new search.\n";
                                                echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
						echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
						echo "</center>\n";
						echo "</form>\n";
						echo "</body></html>\n";
						$ret_val = disconnect();
						exit;
					      }#end if join == and
					  }#end if no records
                                        else #have records
					  {
					    $indiv_table_id_term = join($rec_list,',');
				            $final_query_field_list[] = 'individual_table_id';
				            $final_query_term_array[] = $indiv_table_id_term;
				            $final_query_mode_array[] = 'in';
                                            unset($rec_list);
					  }#end else have records
				      }#end else have records
				    unset($affect_id_array);
                                  }#end foreach search field;
			      }#end if more than one affection field
                            else #only one affection field
			      {
				$affection_name = preg_replace('/_affection_status$/','',$affect_field_list[0]);
				$field_list = array('affection_status_name');
				$affect_id_array = distinctTableQuery('affection_status_id','affection_status_table',$database_id,$field_list,$affection_name,'equal','all');
				if (!is_array($affect_id_array))
				  {
				    $date = date('Y-m-d H:i:s');
				    echo "Error #28: $date<br>\n";
				    echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
				    echo "$affect_id_array<br><br>\n";
				    echo "Please email the above error using the Comments/Help/Support link on the \n";
				    echo "left navigation bar.\n";
				    echo "</form>\n";
				    echo "</body></html>\n";
				    $ret_val = disconnect();
				    exit;
				  }#end error in call to distinctTableQuery
                                if (sizeof($affect_id_array) == '0')
				  {
				    if ($join == 'and')
				      {
					echo "<center>\n";
					echo "Your search of the Individual Table did not yield any individuals.<br>\n";
					echo "Please change your search criteria and try a new search.\n";
                                        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
					echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
					echo "</center>\n";
					echo "</form>\n";
					echo "</body></html>\n";
					$ret_val = disconnect();
					exit;
				      }#end if join == and
				  }#end if no records
                                else #have affections status record
				  {
				    if (sizeof($affect_id_array) == '1') {$affect_id = $affect_id_array[0];}
				    else
				      {
					$date = date('Y-m-d H:i:s');
					echo "Error #29: $date<br>\n";
					echo "The user wanted to search for values of affection status $affection_name.  \n";
					echo "But when queried the affection status table with that name, multiple records were returned.<br><br>\n";
					echo "Please email the above error using the Comments/Help/Support link on the \n";
					echo "left navigation bar.\n";
					echo "</form>\n";
					echo "</body></html>\n";
					$ret_val = disconnect();
					exit;
				      }#end error in data integrity
                                 
                                    $field_list = array('affection_status_id','individual_affection_status');
				    $term_array = array($affect_id,$affect_term_array[0]);
				    $mode_array = array('equal',$affect_mode_array[0]);
				    $rec_list = distinctCompoundTableQuery('individual_table_id','individual_affection_status_link_table',$database_id,$field_list,$term_array,$mode_array,'and','all');
				    if (!is_array($rec_list))
				      {
					$date = date('Y-m-d H:i:s');
					echo "Error #30: $date<br>\n";
					echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
					echo "$rec_list<br><br>\n";
					echo "Please email the above error using the Comments/Help/Support link on the \n";
					echo "left navigation bar.\n";
					echo "</form>\n";
					echo "</body></html>\n";
					$ret_val = disconnect();
					exit;
				      }#end error in call to compoundTableQuery
                                    if (sizeof($rec_list) == '0')
				      {
					if ($join == 'and')
					  {
					    echo "<center>\n";
					    echo "Your search of the Individual Table did not yield any individuals.<br>\n";
					    echo "Please change your search criteria and try a new search.\n";
                                            echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
					    echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
					    echo "</center>\n";
					    echo "</form>\n";
					    echo "</body></html>\n";
					    $ret_val = disconnect();
					    exit;
					  }#end if join == and
                                      }#end if no records
                                    else #have records
				      {
					$indiv_table_id_term = join($rec_list,',');
					$final_query_field_list[] = 'individual_table_id';
					$final_query_term_array[] = $indiv_table_id_term;
					$final_query_mode_array[] = 'in';
                                        unset($rec_list);
				      }#end else have records
				  }#end else have affection status record
                                unset($affect_id_array);
                              }#end else have one affection field
                          }#end if have affection status fields

			$num_of_indivs = countCompoundTableQuery($table_name,$database_id,$final_query_field_list,$final_query_term_array,$final_query_mode_array,$join);
			if (!preg_match('/^\d+$/',$num_of_indivs))
			  {
			    $date = date('Y-m-d H:i:s');
		            echo "Error #31: $date<br>\n";
		            echo "Error in call to countCompoundTableQuery from individual_search.php<br>\n";
		            echo "$num_of_indivs<br><br>\n";
		            echo "Please email the above error using the Comments/Help/Support link on the \n";
		            echo "left navigation bar.\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
		          }#end if error in call to countCompoundTableQuery

			#if ($num_of_indivs > $max_records_to_print)
			#  {
                        #    if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                        #    if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
			#    $indiv_table_id_array = distinctCompoundTableQuery('individual_table_id',$table_name,$database_id,$final_query_field_list,$final_query_term_array,$final_query_mode_array,$join,'all',$order_by);
			#    if (!is_array($indiv_table_id_array))
			#      {
			#	$date = date('Y-m-d H:i:s');
			#	echo "Error #32: $date<br>\n";
			#	echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
			#	echo "$indiv_table_id_array<br><br>\n";
			#	echo "Please email the above error using the Comments/Help/Support link on the \n";
			#	echo "left navigation bar.\n";
			#	echo "</form>\n";
			#	echo "</body></html>\n";
			#	$ret_val = disconnect();
			#	exit;
			#      }#end if (!is_array(indiv_rec_list))
			#    $indiv_table_id_term = join(',',$indiv_table_id_array);
                        #    echo "Your search returned $num_of_indivs individuals.<br>\n";
                        #    tooManyIndividuals($indiv_table_id_term);
                        #    $ret_val = disconnect();
                        #    exit;
                        #  }#end if more than max records to print

			if ($num_of_indivs > ($max_records_to_print_per_page * 5))
                          {
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                            $indiv_table_id_array = distinctCompoundTableQuery('individual_table_id',$table_name,$database_id,$final_query_field_list,$final_query_term_array,$final_query_mode_array,$join,'all',$order_by);
			    if (!is_array($indiv_table_id_array))
			      {
				$date = date('Y-m-d H:i:s');
				echo "Error #33: $date<br>\n";
				echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
				echo "$indiv_table_id_array<br><br>\n";
				echo "Please email the above error using the Comments/Help/Support link on the \n";
				echo "left navigation bar.\n";
				echo "</form>\n";
				echo "</body></html>\n";
				$ret_val = disconnect();
				exit;
			      }#end if (!is_array(indiv_rec_list))
			    $all_indiv_table_id_term = join(',',$indiv_table_id_array);
                            moreThanFivePages($all_indiv_table_id_term);
                            unset($indiv_table_id_array);
                            unset($all_indiv_table_id_term);
                          }#end if more than 5 pages returned

			if ($num_of_indivs > $max_records_to_print_per_page)
			  {
			    $indiv_multiple_pages = 1;
                            $from = '0';
                            $to   = $max_records_to_print_per_page - 1;
                            $range = "$from"."-"."$to";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                            $indiv_rec_list = compoundTableQuery($table_name,$database_id,$final_query_field_list,$final_query_term_array,$final_query_mode_array,$join,$range,$order_by);
                            if (!is_array($indiv_rec_list))
                              {
                                $date = date('Y-m-d H:i:s');
		                echo "Error #34: $date<br>\n";
		                echo "Error in call to compoundTableQuery from individual_search.php<br>\n";
		                echo "$indiv_rec_list<br><br>\n";
		                echo "Please email the above error using the Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (!is_array(indiv_rec_list))
		            if (sizeof($indiv_rec_list) == '0')
                              {
                                echo "<center>\n";
		                echo "Your search of the Individual Table did not yield any individuals.<br>\n";
		                echo "Please try your search again with different search criteria.<br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (sizeof(indiv_rec_list) == '0')
                            $final_function_call   = 'compoundTableQuery';
			    $final_table_name      = $table_name;
			    $final_field_list      = $final_query_field_list;
			    $final_term            = $final_query_term_array;
			    $final_mode            = $final_query_mode_array;
                            $final_join            = $join;
			    $final_order_by        = $order_by;
                            $last_record_retrieved = $max_records_to_print_per_page;
                          }#end more than a single page
                        else #only a single page
			  {
			    $indiv_multiple_pages = 0;
                            $range                = "all";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                            $indiv_rec_list = compoundTableQuery($table_name,$database_id,$final_query_field_list,$final_query_term_array,$final_query_mode_array,$join,$range,$order_by);
                            if (!is_array($indiv_rec_list))
                              {
                                $date = date('Y-m-d H:i:s');
		                echo "Error #35: $date<br>\n";
		                echo "Error in call to compoundTableQuery from individual_search.php<br>\n";
		                echo "$indiv_rec_list<br><br>\n";
		                echo "Please email the above error using the Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (!is_array(indiv_rec_list))
		            if (sizeof($indiv_rec_list) == '0')
                              {
                                echo "<center>\n";
		                echo "Your search of the Individual Table did not yield any individuals.<br>\n";
		                echo "Please try your search again with different search criteria.<br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (sizeof(indiv_rec_list) == '0')
			  }#end else 100 or fewer individuals
                      }#end else sizeof(field_list) > '1'
		   }#end if (table_name == 'individual_table')

		 elseif ($table_name == 'individual_group_table')
		   {
                     if (sizeof($field_list) == '1')
                       {
                         $num_of_modes = sizeof($mode);
                         for ($i='0';$i<$num_of_modes;$i++)
                           {
			     if ($mode[$i] != 'Select Type of Search')
			       {
			         $search_mode = $mode[$i];
			         $search_term = $term[$i];
			       }
		           }#end foreach mode

                         $indiv_table_id_array = distinctTableJoin('individual_table_id',$table_name,'individual_individual_group_link_table',$database_id,$field_list,$search_term,$search_mode,'all');
                         if (!is_array($indiv_table_id_array))
                           {
                             $date = date('Y-m-d H:i:s');
                             echo "Error #36: $date<br>\n";
                             echo "Error in call to distinctTableJoin from individual_search.php<br>\n";
                             echo "$indiv_table_id_array<br><br>\n";
                             echo "Please email the above error using the Comments/Help/Support link on the \n";
		             echo "left navigation bar.\n";
		             echo "</form>\n";
		             echo "</body></html>\n";
		             $ret_val = disconnect();
		             exit;
                           }#end error in call to distinctTableJoin
                         if (sizeof($indiv_table_id_array) == '0')
                           {
                             echo "<center>\n";
			     echo "Your search of the Individual Group Table did not yield any individuals.<br>\n";
			     echo "Please change your search criteria and try a new search.<br>\n";
                             echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
			     echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
			     echo "</center>\n";
			     echo "</form>\n";
			     echo "</body></html>\n";
		 	     $ret_val = disconnect();
		 	     exit;
		           }#end if no individuals
                         $indiv_table_id_term = join($indiv_table_id_array,',');
                         unset($indiv_table_id_array);
                       }#end if only one search field
                     else #more than one search field
                       {
                         $term_array = array();
		         $mode_array = array();
		         $num_of_fields = sizeof($field_list);
		         $num_of_modes  = sizeof($mode);
		         for ($i='0';$i<$num_of_fields;$i++)
		            {
			      $place_on_field_list = ($i + 1);
			      $num_of_modes_seen   = '0';
			      for ($j='0';$j<$num_of_modes;$j++)
			        {
			          if ($mode[$j] != 'Select Type of Search')
			            {
				      $num_of_modes_seen = ($num_of_modes_seen + 1);
				      if ($place_on_field_list == $num_of_modes_seen)
				        {
				          $term_array[] = $term[$j];
				          $mode_array[] = $mode[$j];
				        }#end if right place on list
			            }#end if a real mode
			        }#end foreach mode
		            }#end foreach field
		    
		         $rec_list = compoundTableQuery($table_name,$database_id,$field_list,$term_array,$mode_array,$join,'all');
		         if (!is_array($rec_list))
		           {
                             $date = date('Y-m-d H:i:s');
			     echo "Error #37: $date<br>\n";
			     echo "Error in call to compoundTableQuery from individual_search.php<br>\n";
			     echo "$rec_list<br><br>\n";
			     echo "Please email the above error using the Comments/Help/Support link on the \n";
			     echo "left navigation bar.\n";
			     echo "</form>\n";
			     echo "</body></html>\n";
			     $ret_val = disconnect();
			     exit;
		           }#end error in call to compoundTableQuery
		         if (sizeof($rec_list) == '0')
		           {
			     echo "<center>\n";
			     echo "Your search of the Individual Group Table did not yield any individuals.<br>\n";
			     echo "Please change your search criteria and try a new search.<br>\n";
                             echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
			     echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
			     echo "</center>\n";
			     echo "</form>\n";
			     echo "</body></html>\n";
			     $ret_val = disconnect();
			     exit;
		           }#end if no records
                         $indiv_table_id_array = array();
                         foreach ($rec_list as $rec)
                           {
                             $indiv_group_id = $rec['individual_group_id'];
                             $field_list = array('individual_group_id');
                             $indiv_list_array = distinctTableQuery('individual_table_id','individual_individual_group_link_table',$database_id,$field_list,$indiv_group_id,'equal','all');
                             if (!is_array($indiv_list_array))
                               {
                                 $date = date('Y-m-d H:i:s');
                                 echo "Error #38: $date<br>\n";
                                 echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
                                 echo "$indiv_list_array<br><br>\n";
                                 echo "Please email the above error using the Comments/Help/Support link on the \n";
			         echo "left navigation bar.\n";
			         echo "</form>\n";
			         echo "</body></html>\n";
			         $ret_val = disconnect();
			         exit;
                               }#end error in call to distinctTableQuery
                             if (sizeof($indiv_list_array) > '0')
                               {
                                 foreach ($indiv_list_array as $indiv) {if (!in_array($indiv,$indiv_table_id_array)) {$indiv_table_id_array[] = $indiv;}}
                               }
                           }#end foreach individual group

                         if (sizeof($indiv_table_id_array) == '0')
                           {
                             echo "<center>\n";
			     echo "Your search of the Individual Group Table did not yield any individuals.<br>\n";
			     echo "Please change your search criteria and try a new search.<br>\n";
                             echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
			     echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
			     echo "</center>\n";
			     echo "</form>\n";
			     echo "</body></html>\n";
			     $ret_val = disconnect();
			     exit;
                           }
                         $indiv_table_id_term = join($indiv_table_id_array,',');
                         unset($rec_list);
                         unset($indiv_table_id_array);
                       }#end else more than one search field

                     $field_list = array('individual_table_id');
		     $num_of_indivs = countTableQuery('individual_table',$database_id,$field_list,$indiv_table_id_term,'in');
		     if (!preg_match('/^\d+$/',$num_of_indivs))
		       {
			 $date = date('Y-m-d H:i:s');
                         echo "Error #39: $date<br>\n";
			 echo "Error in call to countTableQuery from individual_search.php<br>\n";
			 echo "$num_of_indivs<br><br>\n";
			 echo "Please email the above error using the Comments/Help/Support link on the \n";
			 echo "left navigation bar.\n";
			 echo "</form>\n";
			 echo "</body></html>\n";
			 $ret_val = disconnect();
			 exit;
		       }#end error in call to countTableQuery

                     #if ($num_of_indivs > $max_records_to_print)
                     #  {
                     #    echo "Your search returned $num_of_indivs individuals.<br>\n";
                     #    tooManyIndividuals($indiv_table_id_term);
                     #    $ret_val = disconnect();
                     #    exit;
                     #  }#end if number of individuals returned > 1000

		     if ($num_of_indivs > ($max_records_to_print_per_page *5))
                       {
                         if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                         if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                         $indiv_table_id_array = distinctTableQuery('individual_table_id','individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in','all',$order_by);
                         if (!is_array($indiv_table_id_array))
                           {
                             $date = date('Y-m-d H:i:s');
			     echo "Error #40: $date<br>\n";
			     echo "Error in call to distincTableQuery from individual_search.php<br>\n";
			     echo "$indiv_table_id_array<br><br>\n";
			     echo "Please email the above error using the Comments/Help/Support link on the \n";
			     echo "left navigation bar.\n";
			     echo "</form>\n";
			     echo "</body></html>\n";
			     $ret_val = disconnect();
			     exit;
			   }#end if error call to distinctTableQuery
                         $all_indiv_table_id_term = join($indiv_table_id_array,',');
                         unset($indiv_table_id_array);

                         moreThanFivePages($all_indiv_table_id_term);
                         unset($all_indiv_table_id_term);
                       }#end if more than 5 pages returned

		     if ($num_of_indivs > $max_records_to_print_per_page)
		       {
			 $indiv_multiple_pages = 1;
                         $from                 = "0";
                         $to                   = $max_records_to_print_per_page - 1;
                         $range                = "$from"."-"."$to";
                         if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                         if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
			 $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list,$indiv_table_id_term,'in',$range,$order_by);
			 if (!is_array($indiv_rec_list))
			   {
			     $date = date('Y-m-d H:i:s');
			     echo "Error #41: $date<br>\n";
			     echo "Error in call to tableQuery from individual_search.php<br>\n";
			     echo "$indiv_rec_list<br><br>\n";
			     echo "Please email the above error using the Comments/Help/Support link on the \n";
			     echo "left navigation bar.\n";
			     echo "</form>\n";
			     echo "</body></html>\n";
			     $ret_val = disconnect();
			     exit;
			   }#end if (!is_array(indiv_rec_list))
                         if (sizeof($indiv_rec_list) == '0')
			   {
			     echo "<center>\n";
			     echo "Your search of the Individual Table did not yield any individuals.<br>\n";
			     echo "Please try your search again with different search criteria.<br>\n";
			     echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
			     echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
			     echo "</center>\n";
			     echo "</form>\n";
			     echo "</body></html>\n";
			     $ret_val = disconnect();
			     exit;
			   }#end if (sizeof(indiv_rec_list) == '0')
			 $final_function_call   = 'tableQuery';
			 $final_table_name      = 'individual_table';
			 $final_field_list      = $field_list;
			 $final_term            = $indiv_table_id_term;
			 $final_mode            = 'in';
			 $final_order_by        = $order_by;
                         $last_record_retrieved = $max_records_to_print_per_page;
                       }#end if more than a single page
                     else #only a single page
		       {
			 $indiv_multiple_pages = 0;
                         $range                = "all";
                         if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                         if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
		         $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list,$indiv_table_id_term,'in',$range,$order_by);
                         if (!is_array($indiv_rec_list))
		           {
			     $date = date('Y-m-d H:i:s');
			     echo "Error #42: $date<br>\n";
			     echo "Error in call to tableQuery from individual_search.php<br>\n";
			     echo "$indiv_rec_list<br><br>\n";
			     echo "Please email the above error using the Comments/Help/Support link on the \n";
			     echo "left navigation bar.\n";
			     echo "</form>\n";
			     echo "</body></html>\n";
			     $ret_val = disconnect();
			     exit;
		           }#end error in call to tableQuery
		         if (sizeof($indiv_rec_list) == '0')
		           {
			     echo "<center>\n";
			     echo "Your search of the Individual Group Table did not yield any individuals.<br>\n";
			     echo "Please change your search criteria and try a new search.<br>\n";
                             echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
			     echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
			     echo "</center>\n";
			     echo "</form>\n";
			     echo "</body></html>\n";
			     $ret_val = disconnect();
			     exit;
		           }#end no individuals
		       }#end else only a single page
		   }#end if (table_name == 'individual_group_table')

		 elseif ($table_name == 'pedigree_table')
                   {
                    if (sizeof($field_list) == '1')
                      {
                        $num_of_modes = sizeof($mode);
                        for ($i = '0'; $i < $num_of_modes; $i++)
                          {
                            if ($mode[$i] != 'Select Type of Search')
                              {
                                $search_term = $term[$i];
                                $search_mode = $mode[$i];
                              }
                          }#end determine which term and mode to use

			if (preg_match('/number_.+_affected_in_pedigree/',$field_list[0]))
			  {
			    preg_match('/number_(.+)_affected_in_pedigree/',$field_list[0],$captured);
			    $affection_name = $captured[1];
			    $field_list = array('affection_status_name');
			    $affect_rec_list = tableQuery('affection_status_table',$database_id,$field_list,$affection_name,'equal','all');
			    if (!is_array($affect_rec_list))
                              {
				$date = date('Y-m-d H:i:s');
				echo "Error #43: $date<br>\n";
				echo "Error in call to tableQuery from individual_search.php<br>\n";
				echo "$affect_rec_list<br><br>\n";
				echo "Please email the above error using the Comments/Help/Support link on the \n";
				echo "left navigation bar.\n";
				echo "</form>\n";
				echo "</body></html>\n";
				$ret_val = disconnect();
				exit;
			      }#end error in call to tableQuery
			    if (sizeof($affect_rec_list) == '0')
			      {
				$date = date('Y-m-d H:i:s');
				echo "There is no affection status in the database with name $affection_name.  \n";
                                echo "It appears that it was deleted from the database before you submitted your request \n";
				echo "to search for individuals based upon its value.  \n";
                                echo "This message was generated at $date.\n";
                                echo "</form>\n";
                                echo "</body></html>\n";
                                $ret_val = disconnect();
                                exit;
			      }#end no records
			    elseif (sizeof($affect_rec_list) == '1') {$affect_rec = $affect_rec_list[0];}
			    else
			      {
				$date = date('Y-m-d H:i:s');
				echo "Error #44: $date<br>\n";
				echo "User wanted to search based upon affection status $affection_name, but \n";
				echo "when queried the affection status table with that name multiple records were returned.<br><br>\n";
				echo "Please email the above error using the Comments/Help/Support link on the \n";
				echo "left navigation bar.\n";
				echo "</form>\n";
				echo "</body></html>\n";
				$ret_val = disconnect();
				exit;
			      }#end error in data integrity
			    unset($affect_rec_list);

			    $field_list = array('affection_status_id','number_affected_in_pedigree');
			    $term_array = array($affect_rec['affection_status_id'],$search_term);
			    $mode_array = array('equal',$search_mode);
			    $ped_affect_link_rec_list = compoundTableQuery('pedigree_affection_status_link_table',$database_id,$field_list,$term_array,$mode_array,'and','all');
                            if (!is_array($ped_affect_link_rec_list))
			      {
				$date = date('Y-m-d H:i:s');
				echo "Error #45: $date<br>\n";
				echo "Error in call to compoundTableQuery from individual_search.php<br>\n";
				echo "$ped_affect_link_rec_list<br><br>\n";
				echo "Please email the above error using the Comments/Help/Support link on the \n";
				echo "left navigation bar.\n";
				echo "</form>\n";
				echo "</body></html>\n";
				$ret_val = disconnect();
				exit;
			      }
			    if (sizeof($ped_affect_link_rec_list) == '0')
			      {
				echo "<center>\n";
				echo "Your search of the Pedigree Table did not yield any individuals.<br>\n";
				echo "Please try your search again with different search criteria.<br>\n";
				echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
				echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
				echo "</center>\n";
				echo "</form>\n";
				echo "</body></html>\n";
				$ret_val = disconnect();
				exit;
			      }#end if no records
			    $ped_table_id_term = "";
			    foreach ($ped_affect_link_rec_list as $ped_affect_link_rec)
			      {
				$ped_table_id_term = "$ped_affect_link_rec[pedigree_table_id],";
			      }
			    $ped_table_id_term = preg_replace('/,$/','',$ped_table_id_term);
                            unset($ped_affect_link_rec_list);
			  }#end if affection status field
			else #pedigree table field
			  {
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer";}
			    $rec_list = distinctTableQuery('pedigree_table_id',$table_name,$database_id,$field_list,$search_term,$search_mode,'all',$order_by);
			    if (!is_array($rec_list))
			      {
                                $date = date('Y-m-d H:i:s');
				echo "Error #46: $date<br>\n";
				echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
				echo "$rec_list<br><br>\n";
				echo "Please email the above error using The Comments/Help/Support link on the \n";
				echo "left navigation bar.\n";
				echo "</form>\n";
				echo "</body></html>\n";
				$ret_val = disconnect();
				exit;
			      }#end if (!is_array(rec_list))
			    if (sizeof($rec_list) == '0')
			      {
				echo "<center>\n";
				echo "Your search of the Pedigree Table did not yield any individuals.<br>\n";
				echo "Please try your search again with different search criteria.<br>\n";
				echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
				echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
				echo "</center>\n";
				echo "</form>\n";
				echo "</body></html>\n";
				$ret_val = disconnect();
				exit;
			      }#end if (sizeof(rec_list) == '0')
			    $ped_table_id_term = join($rec_list,',');
                            unset($rec_list);
			  }#end else pedigree table field

		        $field_list_array = array('pedigree_table_id');
                        $num_of_indivs = countTableQuery('individual_table',$database_id,$field_list_array,$ped_table_id_term,'in');
                        if (!preg_match('/^\d+$/',$num_of_indivs))
                          {
                            $date = date('Y-m-d H:i:s');
                            echo "Error #47: $date<br>\n";
			    echo "Error in call to countTableQuery from individual_search.php<br>\n";
			    echo "$num_of_indivs<br><br>\n";
			    echo "Please email the above error using the Comments/Help/Support link on the \n";
			    echo "left navigation bar.\n";
			    echo "</form>\n";
			    echo "</body></html>\n";
			    $ret_val = disconnect();
			    exit;
			  }#end error in call to countTableQuery

                        #if ($num_of_indivs > $max_records_to_print)
                        #  {
                        #    if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                        #    if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                        #    $indiv_table_id_array = distinctTableQuery('individual_table_id','individual_table',$database_id,$field_list_array,$ped_table_id_term,'in','all',$order_by);
			#    if (!is_array($indiv_table_id_array))
			#      {
			#	$date = date('Y-m-d H:i:s');
			#	echo "Error #48: $date<br>\n";
			#	echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
			#	echo "$indiv_table_id_array<br><br>\n";
			#	echo "Please email the above error using the Comments/Help/Support link on the \n";
			#	echo "left navigation bar.\n";
			#	echo "</form>\n";
			#	echo "</body></html>\n";
			#	$ret_val = disconnect();
			#	exit;
			#      }#end if (!is_array(indiv_rec_list))
			#    $indiv_table_id_term = join(',',$indiv_table_id_array);
                        #    echo "Your search returned $num_of_indivs individuals.<br>\n";
                        #    tooManyIndividuals($indiv_table_id_term);
                        #    $ret_val = disconnect();
                        #    exit;
                        #  }#end if more than max to print

			if ($num_of_indivs > ($max_records_to_print_per_page * 5))
                          {
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                            $indiv_table_id_array = distinctTableQuery('individual_table_id','individual_table',$database_id,$field_list_array,$ped_table_id_term,'in','all',$order_by);
			    if (!is_array($indiv_table_id_array))
			      {
				$date = date('Y-m-d H:i:s');
				echo "Error #49: $date<br>\n";
				echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
				echo "$indiv_table_id_array<br><br>\n";
				echo "Please email the above error using the Comments/Help/Support link on the \n";
				echo "left navigation bar.\n";
				echo "</form>\n";
				echo "</body></html>\n";
				$ret_val = disconnect();
				exit;
			      }#end if (!is_array(indiv_rec_list))
			    $indiv_table_id_term = join(',',$indiv_table_id_array);
                            moreThanFivePages($indiv_table_id_term);
                            unset($indiv_table_id_array);
                          }#end if more than 5 pages returned

			if ($num_of_indivs > $max_records_to_print_per_page)
			  {
			    $indiv_multiple_pages = 1;
                            $from                 = "0";
                            $to                   = $max_records_to_print_per_page - 1;
                            $range                = "$from"."-"."$to";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
			    $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$ped_table_id_term,'in',$range,$order_by);
			    if (!is_array($indiv_rec_list))
			      {
				$date = date('Y-m-d H:i:s');
				echo "Error #50: $date<br>\n";
				echo "Error in call to tableQuery from individual_search.php<br>\n";
				echo "$indiv_rec_list<br><br>\n";
				echo "Please email the above error using the Comments/Help/Support link on the \n";
				echo "left navigation bar.\n";
				echo "</form>\n";
				echo "</body></html>\n";
				$ret_val = disconnect();
				exit;
			      }#end if (!is_array(indiv_rec_list))
                            if (sizeof($indiv_rec_list) == '0')
			      {
				echo "<center>\n";
				echo "Your search of the Pedigree Table did not yield any individuals.<br>\n";
				echo "Please try your search again with different search criteria.<br>\n";
				echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
				echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
				echo "</center>\n";
				echo "</form>\n";
				echo "</body></html>\n";
				$ret_val = disconnect();
				exit;
			      }#end if (sizeof(indiv_rec_list) == '0')
			    $final_function_call   = 'tableQuery';
			    $final_table_name      = 'individual_table';
			    $final_field_list      = $field_list_array;
			    $final_term            = $ped_table_id_term;
			    $final_mode            = 'in';
			    $final_order_by        = $order_by;
                            $last_record_retrieved = $max_records_to_print_per_page;
                          }#end if more than a single page
                        else #only a single page
			  {
			    $indiv_multiple_pages = 0;
                            $range                = "all";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
		            $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$ped_table_id_term,'in',$range,$order_by);
		            if (!is_array($indiv_rec_list))
                              {
                                $date = date('Y-m-d H:i:s');
		                echo "Error #51: $date<br>\n";
		                echo "Error in call to tableQuery from individual_search.php<br>\n";
		                echo "$indiv_rec_list<br><br>\n";
		                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (!is_array(indiv_rec_list))
		            if (sizeof($indiv_rec_list) == '0')
                              {
                                echo "<center>\n";
		                echo "Your search of the Pedigree Table did not yield any individuals.<br>\n";
		                echo "Please try your search again with different search criteria.<br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (sizeof(indiv_rec_list) == '0')
			  }#end else only a single page
                      }#end if sizeof(field_list) == '1'
                    else #sizeof(field_list) > '1'
                      {
                        $affect_field_list = array();
			$affect_term_array = array();
			$affect_mode_array = array();
			$final_query_field_list = array();
                        $final_query_term_array = array();
                        $final_query_mode_array = array();
                        $num_of_fields = sizeof($field_list);
                        $num_of_modes  = sizeof($mode);
                        for ($i = '0'; $i < $num_of_fields; $i++)
                          {
			    if (preg_match('/number_.+_affected_in_pedigree/',$field_list[$i]))
			      {
				$affect_field_list[] = $field_list[$i];
				$place_on_field_list = ($i + 1);
				$num_of_mode_seen    = '0';
				for ($j='0'; $j<$num_of_mode_seen; $j++)
				  {
				    if ($mode[$j] != 'Select Type of Search')
				      {
					$num_of_mode_seen = ($num_of_mode_seen + 1);
					if ($place_on_field_list == $num_of_mode_seen)
					  {
					    $affect_term_array[] = $term[$j];
					    $affect_mode_array[] = $mode[$j];
					  }#end if right place on list
                                      }#end if real mode
                                  }#end foreach mode
			      }#end if affection status field
			    else #pedigree table field
			      {
				$final_query_field_list[] = $field_list[$i];
				$place_on_field_list = ($i + 1);
				$num_of_mode_seen    = '0';
				for ($j='0'; $j<$num_of_mode_seen; $j++)
				  {
				    if ($mode[$j] != 'Select Type of Search')
				      {
					$num_of_mode_seen = ($num_of_mode_seen + 1);
					if ($place_on_field_list == $num_of_mode_seen)
					  {
					    $final_query_term_array[] = $term[$j];
					    $final_query_mode_array[] = $mode[$j];
					  }#end if right place on list
                                      }#end if real mode
                                  }#end foreach mode
			      }#end else pedigree table field
                          }#end build queries

                        if (sizeof($affect_field_list) > '0')
			  {
			    if (sizeof($affect_field_list) > '1')
			      {
				$ped_table_id_array = array();
				for ($i='0'; $i < sizeof($affect_field_list); $i++)
				  {
				    preg_match('/number_(.+)_affected_in_pedigree/',$affect_field_list[$i],$captured);
				    $affection_name = $captured[1];
				    $field_list     = array('affection_status_name');
				    $affect_id_array = distinctTableQuery('affection_status_id','affection_status_table',$database_id,$field_list,$affection_name,'equal','all');
				    if (!is_array($affect_id_array))
				      {
					$date = date('Y-m-d H:i:s');
					echo "Error #52: $date<br>\n";
					echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
					echo "$affect_id_array<br><br>\n";
					echo "Please email the above error using the Comments/Help/Support link on the \n";
					echo "left navigation bar.\n";
					echo "</form>\n";
					echo "</body></html>\n";
					$ret_val = disconnect();
					exit;
				      }#end error in call to distinctTableQuery
                                    if (sizeof($affect_id_array) == '0')
				      {
					if ($join == 'and')
					  {
					    echo "<center>\n";
					    echo "Your search of the Pedigree Table did not yield any individuals.<br>\n";
					    echo "Please change your search criteria and try a new search.\n";
                                            echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
					    echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
					    echo "</center>\n";
					    echo "</form>\n";
					    echo "</body></html>\n";
					    $ret_val = disconnect();
					    exit;
					  }#end if join == and
                                      }#end if no records
                                    else #have records
				      {
					if (sizeof($affect_id_array) == '1') {$affect_id = $affect_id_array[0];}
					else #more than 1 affect_id
					  {
					    $date = date('Y-m-d H:i:s');
					    echo "Error #53: $date<br>\n";
					    echo "User wanted to search using number affected in pedigree for affection $affection_name.  \n";
					    echo "But when queried the affection status table with that name, multiple records were returned.<br><br>\n";
					    echo "Please email the above error using the Comments/Help/Support link on the \n";
					    echo "left navigation bar.\n";
					    echo "</form>\n";
					    echo "</body></html>\n";
					    $ret_val = disconnect();
					    exit;
					  }#end error in data integrity
					unset($affect_id_array);
					     
					$field_list = array('affection_status_id','number_affected_in_pedigree');
					$term_array = array($affect_id,$affect_term_array[$i]);
					$mode_array = array('equal',$affect_mode_array[$i]);
					$rec_list = compoundTableQuery('pedigree_affection_status_link_table',$database_id,$field_list,$term_array,$mode_array,'and','all');
					if (!is_array($rec_list))
					  {
					    $date = date('Y-m-d H:i:s');
					    echo "Error #54: $date<br>\n";
					    echo "Error in call to compoundTableQuery from individual_search.php<br>\n";
					    echo "$rec_list<br><br>\n";
					    echo "Please email the above error using the Comments/Help/Support link on the \n";
					    echo "left navigation bar.\n";
					    echo "</form>\n";
					    echo "</body></html>\n";
					    $ret_val = disconnect();
					    exit;
					  }#end error in call to compoundTableQuery
                                        if (sizeof($rec_list) == '0')
					  {
					    if ($join == 'and')
					      {
						echo "<center>\n";
						echo "Your search of the Pedigree Table did not yield any individuals.<br>\n";
						echo "Please change your search criteria and try a new search.\n";
                                                echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
						echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
						echo "</center>\n";
						echo "</form>\n";
						echo "</body></html>\n";
						$ret_val = disconnect();
						exit;
					      }#end if join == and
                                          }#end if no records
                                        else #have records
					  {
					    foreach ($rec_list as $rec)
					      {
						if (!in_array($rec['pedigree_table_id'],$ped_table_id_array)) {$ped_table_id_array[] = $rec['pedigree_table_id'];}
					      }
					  }#end else have records
					unset($rec_list);
                                      }#end else have records
                                  }#end foreach search field
                                $ped_table_id_term = join($ped_table_id_array,',');
				$final_query_field_list[] = 'pedigree_table_id';
				$final_query_term_array[] = $ped_table_id_term;
				$final_query_mode_array[] = 'in';
                                unset($ped_table_id_array);
			      }#end if more than one affection field
                            else #only one affection field
			      {
				$ped_table_id_term = "";
				preg_match('/number_(.+)_affected_in_pedigree/',$affect_field_list[0],$captured);
				$affection_name = $captured[1];
				$field_list = array('affection_status_name');
				$affect_id_array = distinctTableQuery('affection_status_id','affection_status_table',$database_id,$field_list,$affection_name,'equal','all');
				if (!is_array($affect_id_array))
				  {
				    $date = date('Y-m-d H:i:s');
				    echo "Error #55: $date<br>\n";
				    echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
				    echo "$affect_id_array<br><br>\n";
				    echo "Please email the above error using the Comments/Help/Support link on the \n";
				    echo "left navigation bar.\n";
				    echo "</form>\n";
				    echo "</body></html>\n";
				    $ret_val = disconnect();
				    exit;
				  }#end error in call to distinctTableQuery
				if (sizeof($affect_id_array) == '0')
				  {
				    if ($join == 'and')
				      {
					echo "<center>\n";
					echo "Your search of the Pedigree Table did not yield any individuals.<br>\n";
					echo "Please change your search criteria and try a new search.\n";
                                        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
					echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
					echo "</center>\n";
					echo "</form>\n";
					echo "</body></html>\n";
					$ret_val = disconnect();
					exit;
				      }#end if join == and
				  }#end if no records
                                else #have affections status record
				  {
				    if (sizeof($affect_id_array) == '1') {$affect_id = $affect_id_array[0];}
				    else
				      {
					$date = date('Y-m-d H:i:s');
					echo "Error #56: $date<br>\n";
					echo "The user wanted to search for number affected in pedigree of affection status $affection_name.  \n";
					echo "But when queried the affection status table with that name, multiple records were returned.<br><br>\n";
					echo "Please email the above error using the Comments/Help/Support link on the \n";
					echo "left navigation bar.\n";
					echo "</form>\n";
					echo "</body></html>\n";
					$ret_val = disconnect();
					exit;
				      }#end error in data integrity
				    unset($affect_id_array);
                                 
                                    $field_list = array('affection_status_id','number_affected_in_pedigree');
				    $term_array = array($affect_id,$affect_term_array[0]);
				    $mode_array = array('equal',$affect_mode_array[0]);
				    $rec_list = compoundTableQuery('pedigree_affection_status_link_table',$database_id,$field_list,$term_array,$mode_array,'and','all');
				    if (!is_array($rec_list))
				      {
					$date = date('Y-m-d H:i:s');
					echo "Error #57: $date<br>\n";
					echo "Error in call to compoundTableQuery from individual_search.php<br>\n";
					echo "$rec_list<br><br>\n";
					echo "Please email the above error using the Comments/Help/Support link on the \n";
					echo "left navigation bar.\n";
					echo "</form>\n";
					echo "</body></html>\n";
					$ret_val = disconnect();
					exit;
				      }#end error in call to compoundTableQuery
                                    if (sizeof($rec_list) == '0')
				      {
					if ($join == 'and')
					  {
					    echo "<center>\n";
					    echo "Your search of the Pedigree Table did not yield any individuals.<br>\n";
					    echo "Please change your search criteria and try a new search.\n";
                                            echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
					    echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
					    echo "</center>\n";
					    echo "</form>\n";
					    echo "</body></html>\n";
					    $ret_val = disconnect();
					    exit;
					  }#end if join == and
				      }#end if no records
                                    else #have records
				      {
					foreach ($rec_list as $rec)
					  {
					    $ped_table_id_term.= "$rec[pedigree_table_id],";
					  }
					$ped_table_id_term = preg_replace('/,$/','',$ped_table_id_term);
					$final_query_field_list[] = 'pedigree_table_id';
					$final_query_term_array[] = $ped_table_id_term;
					$final_query_mode_array[] = 'in';
                                        unset($rec_list);
				      }#end else have records
                                  }#end else have affection status record
                              }#end else have one affection field
                          }#end if have affection status fields

                        $pedigree_id_array = distinctCompoundTableQuery('pedigree_table_id',$table_name,$database_id,$final_query_field_list,$final_query_term_array,$final_query_mode_array,$join,'all');
                        if (!is_array($pedigree_id_array))
                          {
                            $date = date('Y-m-d H:i:s');
                            echo "Error #58: $date<br>\n";
                            echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
                            echo "$pedigree_id_array<br><br>\n";
                            echo "Please email the above error using The Comments/Help/Support link on the \n";
		            echo "left navigation bar.\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
                          }#end error in call to distinctCompoundTableQuery
                        if (sizeof($rec_list) == '0')
                          {
                            echo "<center>\n";
		            echo "Your search of the Pedigree Table did not yield any individuals.<br>\n";
		            echo "Please try your search again with different search criteria.<br>\n";
			    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		            echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
                            echo "</center>\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
		          }#end if (sizeof(rec_list) == '0')
                        $pedigree_id_term = join($pedigree_id_array,',');
                        unset($pedigree_id_array);

                        $field_list_array = array('pedigree_table_id');
                        $num_of_indivs = countTableQuery('individual_table',$database_id,$field_list_array,$pedigree_id_term,'in');
                        if (!preg_match('/^\d+$/',$num_of_indivs))
                          {
                            $date = date('Y-m-d H:i:s');
                            echo "Error #59: $date<br>\n";
			    echo "Error in call to countTableQuery from individual_search.php<br>\n";
			    echo "$num_of_indivs<br><br>\n";
			    echo "Please email the above error using the Comments/Help/Support link on the \n";
			    echo "left navigation bar.\n";
			    echo "</form>\n";
			    echo "</body></html>\n";
			    $ret_val = disconnect();
			    exit;
			  }#end error in call to countTableQuery

                        #if ($num_of_indivs > $max_records_to_print)
                        #  {
                        #    if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                        #    if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                        #    $indiv_table_id_array = distinctTableQuery('individual_table_id','individual_table',$database_id,$field_list_array,$pedigree_id_term,'in','all',$order_by);
			#    if (!is_array($indiv_table_id_array))
			#      {
			#	$date = date('Y-m-d H:i:s');
			#	echo "Error #60: $date<br>\n";
			#	echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
			#	echo "$indiv_table_id_array<br><br>\n";
			#	echo "Please email the above error using the Comments/Help/Support link on the \n";
			#	echo "left navigation bar.\n";
			#	echo "</form>\n";
			#	echo "</body></html>\n";
			#	$ret_val = disconnect();
			#	exit;
			#      }#end if (!is_array(indiv_rec_list))
			#    $indiv_table_id_term = join(',',$indiv_table_id_array);
                        #    echo "Your search returned $num_of_indivs individuals.<br>\n";
                        #    tooManyIndividuals($indiv_table_id_term);
                        #    unset($indiv_table_id_array);
                        #    $ret_val = disconnect();
                        #    exit;
                        #  }#end if more than max to print

			if ($num_of_indivs > ($max_records_to_print_per_page * 5))
                          {
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                            $indiv_table_id_array = distinctTableQuery('individual_table_id','individual_table',$database_id,$field_list_array,$pedigree_id_term,'in','all',$order_by);
			    if (!is_array($indiv_table_id_array))
			      {
				$date = date('Y-m-d H:i:s');
				echo "Error #61: $date<br>\n";
				echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
				echo "$indiv_table_id_array<br><br>\n";
				echo "Please email the above error using the Comments/Help/Support link on the \n";
				echo "left navigation bar.\n";
				echo "</form>\n";
				echo "</body></html>\n";
				$ret_val = disconnect();
				exit;
			      }#end if (!is_array(indiv_rec_list))
			    $indiv_table_id_term = join(',',$indiv_table_id_array);
                            moreThanFivePages($indiv_table_id_term);
                            unset($indiv_table_id_array);
                          }#end if more than 5 pages returned

			if ($num_of_indivs > $max_records_to_print_per_page)
			  {
			    $indiv_multiple_pages = 1;
                            $from                 = "0";
                            $to                   = $max_records_to_print_per_page - 1;
                            $range                = "$from"."-"."$to";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
			    $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$pedigree_id_term,'in',$range,$order_by);
			    if (!is_array($indiv_rec_list))
			      {
				$date = date('Y-m-d H:i:s');
				echo "Error #62: $date<br>\n";
				echo "Error in call to tableQuery from individual_search.php<br>\n";
				echo "$indiv_rec_list<br><br>\n";
				echo "Please email the above error using the Comments/Help/Support link on the \n";
				echo "left navigation bar.\n";
				echo "</form>\n";
				echo "</body></html>\n";
				$ret_val = disconnect();
				exit;
			      }#end if (!is_array(indiv_rec_list))
                            if (sizeof($indiv_rec_list) == '0')
			      {
				echo "<center>\n";
				echo "Your search of the Pedigree Table did not yield any individuals.<br>\n";
				echo "Please try your search again with different search criteria.<br>\n";
				echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
				echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
				echo "</center>\n";
				echo "</form>\n";
				echo "</body></html>\n";
				$ret_val = disconnect();
				exit;
			      }#end if (sizeof(indiv_rec_list) == '0')
			    $final_function_call   = 'tableQuery';
			    $final_table_name      = 'individual_table';
			    $final_field_list      = $field_list_array;
			    $final_term            = $pedigree_id_term;
			    $final_mode            = 'in';
			    $final_order_by        = $order_by;
                            $last_record_retrieved = $max_records_to_print_per_page;
                          }#end if more than a single page
                        else #only a single page
			  {
			    $indiv_multiple_pages = 0;
                            $range                = "all";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                            $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$pedigree_id_term,'in',$range,$order_by);
		            if (!is_array($indiv_rec_list))
                              {
                                $date = date('Y-m-d H:i:s');
		                echo "Error #63: $date<br>\n";
		                echo "Error in call to tableQuery from individual_search.php<br>\n";
		                echo "$indiv_rec_list<br><br>\n";
		                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (!is_array(indiv_rec_list))
		            if (sizeof($indiv_rec_list) == '0')
                              {
                                echo "<center>\n";
		                echo "Your search of the Pedigree Table did not yield any individuals.<br>\n";
		                echo "Please try your search again with different search criteria.<br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (sizeof(indiv_rec_list) == '0')
			  }#end else only a single page
                      }#end else sizeof(field_list) > '1'
		   }#end if (table_name == 'pedigree_table')

		 elseif ($table_name == 'pedigree_group_table')
		   {
                     if (sizeof($field_list) == '1')
		       {
			 $num_of_modes = sizeof($mode);
			 for ($i='0';$i<$num_of_modes;$i++)
			   {
			     if ($mode[$i] != 'Select Type of Search')
			       {
				 $search_mode = $mode[$i];
				 $search_term = $term[$i];
			       }
		           }#end foreach mode

                         $ped_table_id_array = distinctTableJoin('pedigree_table_id','pedigree_group_table','pedigree_pedigree_group_link_table',$database_id,$field_list,$search_term,$search_mode,'all');
			 if (!is_array($ped_table_id_array))
			   {
			     $date = date('Y-m-d H:i:s');
			     echo "Error #64: $date<br>\n";
			     echo "Error in call to distinctTableJoin from individual_search.php<br>\n";
			     echo "$ped_table_id_array<br><br>\n";
			     echo "Please email the above error using the Comments/Help/Support link on the \n";
			     echo "left navigation bar.\n";
			     echo "</form>\n";
			     echo "</body></html>\n";
			     $ret_val = disconnect();
			     exit;
			   }#end error in call to distincTableJoin
                         if (sizeof($ped_table_id_array) == '0')
			   {
			     echo "<center>\n";
			     echo "Your search of the Pedigree Group Table did not yield any individuals.<br>\n";
			     echo "Please change your search criteria and try a new search.<br>\n";
                             echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
			     echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
			     echo "</center>\n";
			     echo "</form>\n";
			     echo "</body></html>\n";
			     $ret_val = disconnect();
			     exit;
			   }#end no pedigrees
                         $ped_table_id_term = join($ped_table_id_array,',');
                         unset ($ped_table_id_array);
		       }#end if only one search field
                     else #more than one search field
                       {
			 $term_array = array();
			 $mode_array = array();
			 $num_of_fields = sizeof($field_list);
			 $num_of_modes  = sizeof($mode);
			 for ($i='0';$i<$num_of_fields;$i++)
			   {
			     $place_on_field_list = ($i + 1);
			     $num_of_modes_seen   = '0';
			     for ($j='0';$j<$num_of_modes;$j++)
			       {
				 if ($mode[$j] != 'Select Type of Search')
				   {
				     $num_of_modes_seen = ($num_of_modes_seen + 1);
				     if ($place_on_field_list == $num_of_modes_seen)
				       {
					 $term_array[] = $term[$j];
					 $mode_array[] = $mode[$j];
				       }#end if right place on list
			           }#end if a real mode
			       }#end foreach mode
		           }#end foreach field
		    
		         $ped_group_id_array = distinctCompoundTableQuery('pedigree_group_id',$table_name,$database_id,$field_list,$term_array,$mode_array,$join,'all');
			 if (!is_array($ped_group_id_array))
			   {
			     $date = date('Y-m-d H:i:s');
			     echo "Error #65: $date<br>\n";
			     echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
			     echo "$ped_group_id_array<br><br>\n";
			     echo "Please email the above error using the Comments/Help/Support link on the \n";
			     echo "left navigation bar.\n";
			     echo "</form>\n";
			     echo "</body></html>\n";
			     $ret_val = disconnect();
			     exit;
			   }#end error in call to distinctCompoundTableQuery
		         if (sizeof($ped_group_id_array) == '0')
		           { 
			     echo "<center>\n";
			     echo "Your search of the Pedigree Group Table did not yield any individuals.<br>\n";
			     echo "Please change your search criteria and try a new search.<br>\n";
                             echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
			     echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
			     echo "</center>\n";
			     echo "</form>\n";
			     echo "</body></html>\n";
			     $ret_val = disconnect();
			     exit;
			   }#end if no records
			 $ped_group_id_term = join(',',$ped_group_id_array);
			 unset($ped_group_id_array);

                         $field_list_array = ('pedigree_group_id');
                         $ped_table_id_array = distinctTableQuery('pedigree_table_id','pedigree_pedigree_group_link_table',$database_id,$field_list_array,$ped_group_id_term,'in','all');
			 if (!is_array($ped_table_id_array))
			   {
			     $date = date('Y-m-d H:i:s');
			     echo "Error #66: $date<br>\n";
			     echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
			     echo "$ped_table_id_array<br><br>\n";
			     echo "Please email the above error using the Comments/Help/Support link on the \n";
			     echo "left navigation bar.\n";
			     echo "</form>\n";
			     echo "</body></html>\n";
			     $ret_val = disconnect();
			     exit;
			   }#end error in call to distinctTableQuery
                         if (sizeof($ped_table_id_array) == '0')
			   {
			     echo "<center>\n";
			     echo "Your search of the Pedigree Group Table did not yield any individuals.<br>\n";
			     echo "Please change your search criteria and try a new search.<br>\n";
                             echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
			     echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
			     echo "</center>\n";
			     echo "</form>\n";
			     echo "</body></html>\n";
			     $ret_val = disconnect();
			     exit;
			   }
                         $ped_table_id_term = join($ped_table_id_array,',');
                         unset($ped_table_id_array);
		       }#end else more than one search field

                     $field_list = array('pedigree_table_id');
		     $num_of_indivs = countTableQuery('individual_table',$database_id,$field_list,$ped_table_id_term,'in');
                     if (!preg_match('/^\d+$/',$num_of_indivs))
                       {
                         $date = date('Y-m-d H:i:s');
                         echo "Error #67: $date<br>\n";
			 echo "Error in call to countTableQuery from individual_search.php<br>\n";
			 echo "$num_of_indivs<br><br>\n";
			 echo "Please email the above error using the Comments/Help/Support link on the \n";
			 echo "left navigation bar.\n";
			 echo "</form>\n";
			 echo "</body></html>\n";
			 $ret_val = disconnect();
			 exit;
		       }#end error in call to countTableQuery

                     #if ($num_of_indivs > $max_records_to_print)
                     #  {
                     #    if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                     #    if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                     #    $indiv_table_id_array = distinctTableQuery('individual_table_id','individual_table',$database_id,$field_list,$ped_table_id_term,'in','all',$order_by);
		#	 if (!is_array($indiv_table_id_array))
		#	   {
		#	     $date = date('Y-m-d H:i:s');
		#	     echo "Error #68: $date<br>\n";
		#	     echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
		#	     echo "$indiv_table_id_array<br><br>\n";
		#	     echo "Please email the above error using the Comments/Help/Support link on the \n";
		#	     echo "left navigation bar.\n";
		#	     echo "</form>\n";
		#	     echo "</body></html>\n";
		#	     $ret_val = disconnect();
		#	     exit;
		#	   }#end if (!is_array(indiv_rec_list))
		#	 $indiv_table_id_term = join(',',$indiv_table_id_array);
                #         echo "Your search returned $num_of_indivs individuals.<br>\n";
                #         tooManyIndividuals($indiv_table_id_term);
                #         unset($indiv_table_id_array);
                #         $ret_val = disconnect();
                #         exit;
                #       }#end if more than max # of records

		     if ($num_of_indivs > ($max_records_to_print_per_page * 5))
                       {
                         if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                         if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                         $indiv_table_id_array = distinctTableQuery('individual_table_id','individual_table',$database_id,$field_list,$ped_table_id_term,'in','all',$order_by);
			 if (!is_array($indiv_table_id_array))
			   {
			     $date = date('Y-m-d H:i:s');
			     echo "Error #69: $date<br>\n";
			     echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
			     echo "$indiv_table_id_array<br><br>\n";
			     echo "Please email the above error using the Comments/Help/Support link on the \n";
			     echo "left navigation bar.\n";
			     echo "</form>\n";
			     echo "</body></html>\n";
			     $ret_val = disconnect();
			     exit;
			   }#end if (!is_array(indiv_rec_list))
			 $indiv_table_id_term = join(',',$indiv_table_id_array);
                         moreThanFivePages($indiv_table_id_term);
                         unset($indiv_table_id_array);
                       }#end if more than 5 pages

		     if ($num_of_indivs > $max_records_to_print_per_page)
		       {
			 $indiv_multiple_pages = 1;
                         $from                 = "0";
                         $to                   = $max_records_to_print_per_page - 1;
                         $range                = "$from"."-"."$to";
                         if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                         if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
			 $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list,$ped_table_id_term,'in',$range,$order_by);
			 if (!is_array($indiv_rec_list))
			   {
			     $date = date('Y-m-d H:i:s');
			     echo "Error #70: $date<br>\n";
			     echo "Error in call to tableQuery from individual_search.php<br>\n";
			     echo "$indiv_rec_list<br><br>\n";
			     echo "Please email the above error using the Comments/Help/Support link on the \n";
			     echo "left navigation bar.\n";
			     echo "</form>\n";
			     echo "</body></html>\n";
			     $ret_val = disconnect();
			     exit;
			   }#end if (!is_array(indiv_rec_list))
                         if (sizeof($indiv_rec_list) == '0')
			   {
			     echo "<center>\n";
			     echo "Your search of the Pedigree Group Table did not yield any individuals.<br>\n";
			     echo "Please try your search again with different search criteria.<br>\n";
			     echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
			     echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
			     echo "</center>\n";
			     echo "</form>\n";
			     echo "</body></html>\n";
			     $ret_val = disconnect();
			     exit;
			   }#end if (sizeof(indiv_rec_list) == '0')
			 $final_function_call   = 'tableQuery';
			 $final_table_name      = 'individual_table';
			 $final_field_list      = $field_list;
			 $final_term            = $ped_table_id_term;
			 $final_mode            = 'in';
			 $final_order_by        = $order_by;
                         $last_record_retrieved = $max_records_to_print_per_page;
                       }#end if more than one page of records
                     else #only a single page
		       {
			 $indiv_multiple_pages = 0;
                         $range                = "all";
                         if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                         if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                         $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list,$ped_table_id_term,'in',$range,$order_by);
		         if (!is_array($indiv_rec_list))
		           {
			     $date = date('Y-m-d H:i:s');
			     echo "Error #71: $date<br>\n";
			     echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
			     echo "$indiv_rec_list<br><br>\n";
			     echo "Please email the above error using the Comments/Help/Support link on the \n";
			     echo "left navigation bar.\n";
			     echo "</form>\n";
			     echo "</body></html>\n";
			     $ret_val = disconnect();
			     exit;
		           }#end error in call to distinctTableQuery
		         if (sizeof($indiv_rec_list) == '0')
		           {
			     echo "<center>\n";
			     echo "Your search of the Pedigree Group Table did not yield any individuals.<br>\n";
			     echo "Please change your search criteria and try a new search.\n";
                             echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
			     echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
			     echo "</center>\n";
			     echo "</form>\n";
			     echo "</body></html>\n";
			     $ret_val = disconnect();
			     exit;
		           }#end if no records
		       }#end else only a single page
		   }#end if (table_name == 'pedigree_group_table')

		 elseif ($table_name == 'gene_table')
                   {
                    if (sizeof($field_list) == '1')
                      {
                        $num_of_modes = sizeof($mode);
                        for ($i = '0'; $i < $num_of_modes; $i++)
                          {
                            if ($mode[$i] != 'Select Type of Search')
                              {
                                $search_term = $term[$i];
                                $search_mode = $mode[$i];
                              }
                          }#end determine which term and mode to use

		        $rec_list = distinctTableJoin('marker_id',$table_name,'marker_table',$database_id,$field_list,$search_term,$search_mode,'all','marker_id');
		        if (!is_array($rec_list))
                          {
                            $date = date('Y-m-d H:i:s');
		            echo "Error #72: $date<br>\n";
		            echo "Error in call to distinctTableJoin from individual_search.php<br>\n";
		            echo "$rec_list<br><br>\n";
		            echo "Please email the above error using The Comments/Help/Support link on the \n";
		            echo "left navigation bar.\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
		          }#end if (!is_array(rec_list))
		        if (sizeof($rec_list) == '0')
                          {
                            echo "<center>\n";
		            echo "Your search of the Gene Table did not yield any individuals.<br>\n";
		            echo "Please try your search again with different search criteria.<br>\n";
			    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		            echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
                            echo "</center>\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
		          }#end if (sizeof(rec_list) == '0')
		        $term = join($rec_list,',');

		        $field_list_array = array('marker_id');
		        $indiv_table_id_array = distinctTableQuery('individual_table_id','genotype_table',$database_id,$field_list_array,$term,'in','all');
		        if (!is_array($indiv_table_id_array))
                          {
                            $date = date('Y-m-d H:i:s');
		            echo "Error #73: $date<br>\n";
		            echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
		            echo "$indiv_table_id_array<br><br>\n";
		            echo "Please email the above error using The Comments/Help/Support link on the \n";
		            echo "left navigation bar.\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
		          }#end if (!is_array(rec_list))
		        if (sizeof($indiv_table_id_array) == '0')
                          {
                            echo "<center>\n";
		            echo "Your search of the Gene Table did not yield any individuals.<br>\n";
		            echo "Please try your search again with different search criteria.<br>\n";
			    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		            echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
                            echo "</center>\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
		          }#end if (sizeof(rec_list) == '0')
		        $indiv_table_id_term = join($indiv_table_id_array,',');
			unset($indiv_table_id_array);

                        $field_list_array = array('individual_table_id');
                        $num_of_indivs = countTableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in');
                        if (!preg_match('/^\d+$/',$num_of_indivs))
                          {
                            $date = date('Y-m-d H:i:s');
                            echo "Error #74: $date<br>\n";
			    echo "Error in call to countTableQuery from individual_search.php<br>\n";
			    echo "$num_of_indivs<br><br>\n";
			    echo "Please email the above error using the Comments/Help/Support link on the \n";
			    echo "left navigation bar.\n";
			    echo "</form>\n";
			    echo "</body></html>\n";
			    $ret_val = disconnect();
			    exit;
		          }#end error in call to countTableQuery

                        #if ($num_of_indivs > $max_records_to_print)
                        #  {
                        #    echo "Your search returned $num_of_indivs individuals.<br>\n";
                        #    tooManyIndividuals($indiv_table_id_term);
                        #    $ret_val = disconnect();
                        #    exit;
                        #  }#end if more than max to print

		        if ($num_of_indivs > ($max_records_to_print_per_page * 5))
                          {
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                            $indiv_table_id_array = distinctTableQuery('individual_table_id','individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in','all',$order_by);
                            if (!is_array($indiv_table_id_array))
                              {
                                $date = date('Y-m-d H:i:s');
			        echo "Error #75: $date<br>\n";
			        echo "Error in call to distincTableQuery from individual_search.php<br>\n";
			        echo "$indiv_table_id_array<br><br>\n";
			        echo "Please email the above error using the Comments/Help/Support link on the \n";
			        echo "left navigation bar.\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if error call to distinctTableQuery
                            $all_indiv_table_id_term = join($indiv_table_id_array,',');
                            unset($indiv_table_id_array);

                            moreThanFivePages($all_indiv_table_id_term);
                            unset($all_indiv_table_id_term);
                          }#end if more than 5 pages returned

		        if ($num_of_indivs > $max_records_to_print_per_page)
		          {
			    $indiv_multiple_pages = 1;
                            $from                 = "0";
                            $to                   = $max_records_to_print_per_page - 1;
                            $range                = "$from"."-"."$to";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
			    $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in',$range,$order_by);
			    if (!is_array($indiv_rec_list))
			      {
			        $date = date('Y-m-d H:i:s');
			        echo "Error #76: $date<br>\n";
			        echo "Error in call to tableQuery from individual_search.php<br>\n";
			        echo "$indiv_rec_list<br><br>\n";
			        echo "Please email the above error using the Comments/Help/Support link on the \n";
			        echo "left navigation bar.\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if (!is_array(indiv_rec_list))
                            if (sizeof($indiv_rec_list) == '0')
			      {
			        echo "<center>\n";
			        echo "Your search of the Gene Table did not yield any individuals.<br>\n";
			        echo "Please try your search again with different search criteria.<br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
			        echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
			        echo "</center>\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if (sizeof(indiv_rec_list) == '0')
			    $final_function_call   = 'tableQuery';
			    $final_table_name      = 'individual_table';
			    $final_field_list      = $field_list_array;
			    $final_term            = $indiv_table_id_term;
			    $final_mode            = 'in';
			    $final_order_by        = $order_by;
                            $last_record_retrieved = $max_records_to_print_per_page;
                          }#end if more than one page
                        else #only a single page
		          {
			    $indiv_multiple_pages = 0;
                            $range                = "all";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
		            $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in',$range,$order_by);
		            if (!is_array($indiv_rec_list))
                              {
                                $date = date('Y-m-d H:i:s');
		                echo "Error #77: $date<br>\n";
		                echo "Error in call to tableQuery from individual_search.php<br>\n";
		                echo "$indiv_rec_list<br><br>\n";
		                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (!is_array(indiv_rec_list))
		            if (sizeof($indiv_rec_list) == '0')
                              {
                                echo "<center>\n";
		                echo "Your search of the Gene Table did not yield any individuals.<br>\n";
		                echo "Please try your search again with different search criteria.<br>\n";
                                echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (sizeof(indiv_rec_list) == '0')
			  }#end else only a single page
                     }#end if sizeof(field_list) == '1'
                    else #sizeof(field_list) > '1'
                      {
                        $term_array = array();
                        $mode_array = array();
                        $num_of_fields = sizeof($field_list);
                        $num_of_modes  = sizeof($mode);
                        for ($i=0; $i<$num_of_fields; $i++)
                          {
                            $place_on_field_list = ($i + 1);
                            $num_of_mode_seen    = '0';
                            for ($j='0'; $j<$num_of_modes; $j++)
                              {
                                if ($mode[$j] != 'Select Type of Search')
                                  {
                                    $num_of_mode_seen = ($num_of_mode_seen + 1);
                                    if ($place_on_field_list == $num_of_mode_seen)
                                      {
                                        $term_array[] = $term[$j];
                                        $mode_array[] = $mode[$j];
                                      }#end if right place on list
                                  }#end if real mode
                              }#end foreach mode
                          }

                        $gene_id_array = distinctCompoundTableQuery('gene_id',$table_name,$database_id,$field_list,$term_array,$mode_array,$join,'all');
                        if (!is_array($gene_id_array))
                          {
                            $date = date('Y-m-d H:i:s');
                            echo "Error #78: $date<br>\n";
                            echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
                            echo "$gene_id_array<br><br>\n";
                            echo "Please email the above error using The Comments/Help/Support link on the \n";
		            echo "left navigation bar.\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
                          }#end error in call to compoundTableQuery
                        if (sizeof($gene_id_array) == '0')
                          {
                            echo "<center>\n";
		            echo "Your search of the Gene Table did not yield any individuals.<br>\n";
		            echo "Please try your search again with different search criteria.<br>\n";
                            echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		            echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                            echo "</center>\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
                          }#end if sizeof(rec_list) == '0'
                        $gene_id_term = join($gene_id_array,',');
                        unset($gene_id_array);

                        $field_list_array = array('gene_id');
                        $marker_id_array = distinctTableQuery('marker_id','marker_table',$database_id,$field_list_array,$gene_id_term,'in','all','marker_id');
		        if (!is_array($marker_id_array))
                          {
                            $date = date('Y-m-d H:i:s');
		            echo "Error #79: $date<br>\n";
		            echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
		            echo "$marker_id_array<br><br>\n";
		            echo "Please email the above error using The Comments/Help/Support link on the \n";
		            echo "left navigation bar.\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
		          }#end if (!is_array(rec_list))
		        if (sizeof($marker_id_array) == '0')
                          {
                            echo "<center>\n";
		            echo "Your search of the Gene Table did not yield any individuals.<br>\n";
		            echo "Please try your search again with different search criteria.<br>\n";
			    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		            echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
                            echo "</center>\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
		          }#end if (sizeof(rec_list) == '0')
		        $marker_id_term = join($marker_id_array,',');
                        unset($marker_id_array);

		        $field_list_array = array('marker_id');
		        $indiv_table_id_array = distinctTableQuery('individual_table_id','genotype_table',$database_id,$field_list_array,$marker_id_term,'in','all');
		        if (!is_array($indiv_table_id_array))
                          {
                            $date = date('Y-m-d H:i:s');
		            echo "Error #80: $date<br>\n";
		            echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
		            echo "$indiv_table_id_array<br><br>\n";
		            echo "Please email the above error using The Comments/Help/Support link on the \n";
		            echo "left navigation bar.\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
		          }#end if (!is_array(rec_list))
		        if (sizeof($indiv_table_id_array) == '0')
                          {
                            echo "<center>\n";
		            echo "Your search of the Gene Table did not yield any individuals.<br>\n";
		            echo "Please try your search again with different search criteria.<br>\n";
			    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		            echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
                            echo "</center>\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
		          }#end if (sizeof(rec_list) == '0')
		        $indiv_table_id_term = join($indiv_table_id_array,',');
			unset($indiv_table_id_array);

		        $field_list_array = array('individual_table_id');
			$num_of_indivs = countTableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in');
			if (!preg_match('/^\d+$/',$num_of_indivs))
                          {
                            $date = date('Y-m-d H:i:s');
                            echo "Error #81: $date<br>\n";
			    echo "Error in call to countTableQuery from individual_search.php<br>\n";
			    echo "$num_of_indivs<br><br>\n";
			    echo "Please email the above error using the Comments/Help/Support link on the \n";
			    echo "left navigation bar.\n";
			    echo "</form>\n";
			    echo "</body></html>\n";
			    $ret_val = disconnect();
			    exit;
		          }#end error in call to countTableQuery

                        #if ($num_of_indivs > $max_records_to_print)
                        #  {
                        #    echo "Your search returned $num_of_indivs individuals.<br>\n";
                        #    tooManyIndividuals($indiv_table_id_term);
                        #    $ret_val = disconnect();
                        #    exit;
                        #  }#end if more than max

		        if ($num_of_indivs > ($max_records_to_print_per_page * 5))
                          {
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                            $indiv_table_id_array = distinctTableQuery('individual_table_id','individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in','all',$order_by);
                            if (!is_array($indiv_table_id_array))
                              {
                                $date = date('Y-m-d H:i:s');
			        echo "Error #82: $date<br>\n";
			        echo "Error in call to distincTableQuery from individual_search.php<br>\n";
			        echo "$indiv_table_id_array<br><br>\n";
			        echo "Please email the above error using the Comments/Help/Support link on the \n";
			        echo "left navigation bar.\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if error call to distinctTableQuery
                            $all_indiv_table_id_term = join($indiv_table_id_array,',');
                            unset($indiv_table_id_array);

                            moreThanFivePages($all_indiv_table_id_term);
                            unset($all_indiv_table_id_term);
                          }#end if more than 5 pages returned

		        if ($num_of_indivs > $max_records_to_print_per_page)
		          {
			    $indiv_multiple_pages = 1;
                            $from                 = "0";
                            $to                   = $max_records_to_print_per_page - 1;
                            $range                = "$from"."-"."$to";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
			    $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in',$range,$order_by);
			    if (!is_array($indiv_rec_list))
			      {
			        $date = date('Y-m-d H:i:s');
			        echo "Error #83: $date<br>\n";
			        echo "Error in call to tableQuery from individual_search.php<br>\n";
			        echo "$indiv_rec_list<br><br>\n";
			        echo "Please email the above error using the Comments/Help/Support link on the \n";
			        echo "left navigation bar.\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if (!is_array(indiv_rec_list))
                            if (sizeof($indiv_rec_list) == '0')
			      {
			        echo "<center>\n";
			        echo "Your search of the Gene Table did not yield any individuals.<br>\n";
			        echo "Please try your search again with different search criteria.<br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
			        echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
			        echo "</center>\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if (sizeof(indiv_rec_list) == '0')
			    $final_function_call   = 'tableQuery';
			    $final_table_name      = 'individual_table';
			    $final_field_list      = $field_list_array;
			    $final_term            = $indiv_table_id_term;
			    $final_mode            = 'in';
			    $final_order_by        = $order_by;
                            $last_record_retrieved = $max_records_to_print_per_page;
                          }#end if more than a single page
                        else #only a single page
		          {
			    $indiv_multiple_pages = 0;
                            $range                = "all";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
		            $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in',$range,$order_by);
		            if (!is_array($indiv_rec_list))
                              {
                                $date = date('Y-m-d H:i:s');
		                echo "Error #84: $date<br>\n";
		                echo "Error in call to tableQuery from individual_search.php<br>\n";
		                echo "$indiv_rec_list<br><br>\n";
		                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (!is_array(indiv_rec_list))
		            if (sizeof($indiv_rec_list) == '0')
                              {
                                echo "<center>\n";
		                echo "Your search of the Gene Table did not yield any individuals.<br>\n";
		                echo "Please try your search again with different search criteria.<br>\n";
                                echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (sizeof(indiv_rec_list) == '0')
			  }#end else only a single page
                      }#end else sizeof(field_list) > '1'
		   }#end if (table_name == 'gene_table')

		 elseif ($table_name == 'marker_table')
                   {
                    if (sizeof($field_list) == '1')
                      {
                        $num_of_modes = sizeof($mode);
                        for ($i = '0'; $i < $num_of_modes; $i++)
                          {
                            if ($mode[$i] != 'Select Type of Search')
                              {
                                $search_term = $term[$i];
                                $search_mode = $mode[$i];
                              }
                          }#end determine which term and mode to use

		        $indiv_table_id_array = distinctTableJoin('individual_table_id',$table_name,'genotype_table',$database_id,$field_list,$search_term,$search_mode,'all');
		        if (!is_array($indiv_table_id_array))
                          {
                            $date = date('Y-m-d H:i:s');
		            echo "Error #85: $date<br>\n";
		            echo "Error in call to distinctTableJoin from individual_search.php<br>\n";
		            echo "$indiv_table_id_array<br><br>\n";
		            echo "Please email the above error using The Comments/Help/Support link on the \n";
		            echo "left navigation bar.\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
		          }#end if (!is_array(rec_list))
		        if (sizeof($indiv_table_id_array) == '0')
                          {
                            echo "<center>\n";
		            echo "Your search of the Marker Table did not yield any individuals.<br>\n";
		            echo "Please try your search again with different search criteria.<br>\n";
			    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		            echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                            echo "</center>\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
		          }#end if (sizeof(rec_list) == '0')
		        $indiv_table_id_term = join($indiv_table_id_array,',');
			unset($indiv_table_id_array);

		        $field_list_array = array('individual_table_id');
			$num_of_indivs = countTableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in');
			if (!preg_match('/^\d+$/',$num_of_indivs))
                          {
                            $date = date('Y-m-d H:i:s');
                            echo "Error #86: $date<br>\n";
			    echo "Error in call to countTableQuery from individual_search.php<br>\n";
			    echo "$num_of_indivs<br><br>\n";
			    echo "Please email the above error using the Comments/Help/Support link on the \n";
			    echo "left navigation bar.\n";
			    echo "</form>\n";
			    echo "</body></html>\n";
			    $ret_val = disconnect();
			    exit;
		          }#end error in call to countTableQuery

                        #if ($num_of_indivs > $max_records_to_print)
                        #  {
                        #    echo "Your search returned $num_of_indivs individuals.<br>\n";
                        #    tooManyIndividuals($indiv_table_id_term);
                        #    $ret_val = disconnect();
                        #    exit;
                        #  }#end if more than max

		        if ($num_of_indivs > ($max_records_to_print_per_page * 5))
                          {
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                            $indiv_table_id_array = distinctTableQuery('individual_table_id','individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in','all',$order_by);
                            if (!is_array($indiv_table_id_array))
                              {
                                $date = date('Y-m-d H:i:s');
			        echo "Error #87: $date<br>\n";
			        echo "Error in call to distincTableQuery from individual_search.php<br>\n";
			        echo "$indiv_table_id_array<br><br>\n";
			        echo "Please email the above error using the Comments/Help/Support link on the \n";
			        echo "left navigation bar.\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if error call to distinctTableQuery
                            $all_indiv_table_id_term = join($indiv_table_id_array,',');
                            unset($indiv_table_id_array);

                            moreThanFivePages($all_indiv_table_id_term);
                            unset($all_indiv_table_id_term);
                          }#end if more than 5 pages returned

		        if ($num_of_indivs > $max_records_to_print_per_page)
		          {
			    $indiv_multiple_pages = 1;
                            $from                 = "0";
                            $to                   = $max_records_to_print_per_page - 1;
                            $range                = "$from"."-"."$to";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
			    $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in',$range,$order_by);
			    if (!is_array($indiv_rec_list))
			      {
			        $date = date('Y-m-d H:i:s');
			        echo "Error #88: $date<br>\n";
			        echo "Error in call to tableQuery from individual_search.php<br>\n";
			        echo "$indiv_rec_list<br><br>\n";
			        echo "Please email the above error using the Comments/Help/Support link on the \n";
			        echo "left navigation bar.\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if (!is_array(indiv_rec_list))
                            if (sizeof($indiv_rec_list) == '0')
			      {
			        echo "<center>\n";
			        echo "Your search of the Marker Table did not yield any individuals.<br>\n";
			        echo "Please try your search again with different search criteria.<br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
			        echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
			        echo "</center>\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if (sizeof(indiv_rec_list) == '0')
			    $final_function_call   = 'tableQuery';
			    $final_table_name      = 'individual_table';
			    $final_field_list      = $field_list_array;
			    $final_term            = $indiv_table_id_term;
			    $final_mode            = 'in';
			    $final_order_by        = $order_by;
                            $last_record_retrieved = $max_records_to_print_per_page;
                          }#end if more than a single page
                        else #only a single page
		          {
			    $indiv_multiple_pages = 0;
                            $range                = "all";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
		            $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$term,'in',$range,$order_by);
		            if (!is_array($indiv_rec_list))
                              {
                                $date = date('Y-m-d H:i:s');
		                echo "Error #89: $date<br>\n";
		                echo "Error in call to tableQuery from individual_search.php<br>\n";
		                echo "$indiv_rec_list<br><br>\n";
		                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (!is_array(indiv_rec_list))
		            if (sizeof($indiv_rec_list) == '0')
                              {
                                echo "<center>\n";
		                echo "Your search of the Marker Table did not yield any individuals.<br>\n";
		                echo "Please try a new search with different search criteria.<br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (sizeof(indiv_rec_list) == '0')
			  }#end else only a single page
                      }#end if sizeof(field_list) == '1'
                    else #sizeof(field_list) > '0'
                      {
                        $term_array = array();
                        $mode_array = array();
                        $num_of_fields = sizeof($field_list);
                        $num_of_modes  = sizeof($mode);
                        for ($i='0'; $i<$num_of_fields; $i++)
                          {
                            $place_on_field_list = ($i + 1);
                            $num_of_mode_seen    = '0';
                            for ($j='0'; $j<$num_of_modes; $j++)
                              {
                                if ($mode[$j] != 'Select Type of Search')
                                  {
                                    $num_of_mode_seen = ($num_of_mode_seen + 1);
                                    if ($place_on_field_list == $num_of_mode_seen)
                                      {
                                        $term_array[] = $term[$j];
                                        $mode_array[] = $mode[$j];
                                      }#end if right place on list
                                  }#end if real mode
                              }#end foreach mode
                          }
 
                        $marker_id_array = distinctCompoundTableQuery('marker_id',$table_name,$database_id,$field_list,$term_array,$mode_array,$join,'all');
                        if (!is_array($marker_id_array))
                          {
                            $date = date('Y-m-d H:i:s');
                            echo "Error #90: $date<br>\n";
                            echo "Error in call to compoundTableQuery from individual_search.php<br>\n";
                            echo "$marker_id_array<br><br>\n";
                            echo "Please email the above error using The Comments/Help/Support link on the \n";
		            echo "left navigation bar.\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
                          }#end error in call to compoundTableQuery
                        if (sizeof($rec_list) == '0')
                          {
                            echo "<center>\n";
		            echo "Your search of the Marker Table did not yield any individuals.<br>\n";
		            echo "Please try a new search with different search criteria.<br>\n";
			    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		            echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                            echo "</center>\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
                          }#end if sizeof(rec_list) == '0'
                        $marker_id_term = join($marker_id_array,',');
			unset($marker_id_array);

                        $field_list_array = array('marker_id');
                        $indiv_table_id_array = distinctTableQuery('individual_table_id','genotype_table',$database_id,$field_list_array,$marker_id_term,'in','all');
		        if (!is_array($indiv_table_id_array))
                          {
                            $date = date('Y-m-d H:i:s');
		            echo "Error #91: $date<br>\n";
		            echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
		            echo "$indiv_table_id_array<br><br>\n";
		            echo "Please email the above error using The Comments/Help/Support link on the \n";
		            echo "left navigation bar.\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
		          }#end if (!is_array(rec_list))
		        if (sizeof($indiv_table_id_array) == '0')
                          {
                            echo "<center>\n";
		            echo "Your search of the Marker Table did not yield any individuals.<br>\n";
		            echo "Please try your search again with different search criteria.<br>\n";
			    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		            echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                            echo "</center>\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
		          }#end if (sizeof(rec_list) == '0')
		        $indiv_table_id_term = join($indiv_table_id_array,',');
			unset($indiv_table_id_array);

		        $field_list_array = array('individual_table_id');
			$num_of_indivs = countTableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in');
			if (!preg_match('/^\d+$/',$num_of_indivs))
                          {
                            $date = date('Y-m-d H:i:s');
                            echo "Error #92: $date<br>\n";
			    echo "Error in call to countTableQuery from individual_search.php<br>\n";
			    echo "$num_of_indivs<br><br>\n";
			    echo "Please email the above error using the Comments/Help/Support link on the \n";
			    echo "left navigation bar.\n";
			    echo "</form>\n";
			    echo "</body></html>\n";
			    $ret_val = disconnect();
			    exit;
		          }#end error in call to countTableQuery

                        #if ($num_of_indivs > $max_records_to_print)
                        #  {
                        #    echo "Your search returned $num_of_indivs individuals.<br>\n";
                        #    tooManyIndividuals($indiv_table_id_term);
                        #    $ret_val = disconnect();
                        #    exit;
                        #  }#end if more than max

		        if ($num_of_indivs > ($max_records_to_print_per_page * 5))
                          {
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                            $indiv_table_id_array = distinctTableQuery('individual_table_id','individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in','all',$order_by);
                            if (!is_array($indiv_table_id_array))
                              {
                                $date = date('Y-m-d H:i:s');
			        echo "Error #93: $date<br>\n";
			        echo "Error in call to distincTableQuery from individual_search.php<br>\n";
			        echo "$indiv_table_id_array<br><br>\n";
			        echo "Please email the above error using the Comments/Help/Support link on the \n";
			        echo "left navigation bar.\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if error call to distinctTableQuery
                            $all_indiv_table_id_term = join($indiv_table_id_array,',');
                            unset($indiv_table_id_array);

                            moreThanFivePages($all_indiv_table_id_term);
                            unset($all_indiv_table_id_term);
                          }#end if more than 5 pages returned

		        if ($num_of_indivs > $max_records_to_print_per_page)
		          {
			    $indiv_multiple_pages = 1;
                            $from                 = "0";
                            $to                   = $max_records_to_print_per_page - 1;
                            $range                = "$from"."-"."$to";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
			    $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in',$range,$order_by);
			    if (!is_array($indiv_rec_list))
			      {
			        $date = date('Y-m-d H:i:s');
			        echo "Error #94: $date<br>\n";
			        echo "Error in call to tableQuery from individual_search.php<br>\n";
			        echo "$indiv_rec_list<br><br>\n";
			        echo "Please email the above error using the Comments/Help/Support link on the \n";
			        echo "left navigation bar.\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if (!is_array(indiv_rec_list))
                            if (sizeof($indiv_rec_list) == '0')
			      {
			        echo "<center>\n";
			        echo "Your search of the Marker Table did not yield any individuals.<br>\n";
			        echo "Please try your search again with different search criteria.<br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
			        echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
			        echo "</center>\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if (sizeof(indiv_rec_list) == '0')
			    $final_function_call   = 'tableQuery';
			    $final_table_name      = 'individual_table';
			    $final_field_list      = $field_list_array;
			    $final_term            = $indiv_table_id_term;
			    $final_mode            = 'in';
			    $final_order_by        = $order_by;
                            $last_record_retrieved = $max_records_to_print_per_page;
                          }#end if more than one page
                        else #only a single page
		          {
			    $indiv_multiple_pages = 0;
                            $range                = "all";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
		            $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in',$range,$order_by);
		            if (!is_array($indiv_rec_list))
                              {
                                $date = date('Y-m-d H:i:s');
		                echo "Error #95: $date<br>\n";
		                echo "Error in call to tableQuery from individual_search.php<br>\n";
		                echo "$indiv_rec_list<br><br>\n";
		                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (!is_array(indiv_rec_list))
		            if (sizeof($indiv_rec_list) == '0')
                              {
                                echo "<center>\n";
		                echo "Your search of the Marker Table did not yield any individuals.<br>\n";
		                echo "Please try a new search with different search criteria.<br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (sizeof(indiv_rec_list) == '0')
			  }#end else only a single page
                      }#end else sizeof(field_list) > '1'
		   }#end if (table_name == 'marker_table')

                  elseif ($table_name == 'map_table')
                   {
                    if (sizeof($field_list) == '1')
                      {
                        $num_of_modes = sizeof($mode);
                        for ($i = '0'; $i < $num_of_modes; $i++)
                          {
                            if ($mode[$i] != 'Select Type of Search')
                              {
                                $search_term = $term[$i];
                                $search_mode = $mode[$i];
                              }
                          }#end determine which term and mode to use

                        if (($field_list[0] == 'marker_name') or ($field_list[0] == 'chromosome'))
                          {
                            $marker_id_array = distinctTableJoin('marker_id','marker_table','map_marker_link_table',$database_id,$field_list,$search_term,$search_mode,'all');
                            if (!is_array($marker_id_array))
                              {
                                $date = date('Y-m-d H:i:s');
                                echo "Error #96:$date<br>\n";
                                echo "Error in call to distinctTableJoin from individual_search.php<br>\n";
                                echo "$marker_id_array<br>\n";
                                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
                              }#end error in call to distinctTableJoin
                            if (sizeof($marker_id_array) == '0')
                              {
                                echo "<center>\n";
		                echo "Your search of the Map Table did not yield any individuals.<br>\n";
		                echo "Please try a new search with different search criteria.<br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
                              }#end if no records
                          }#end if search field is a marker_table field
                        else #map table field
                          {
                            $marker_id_array = distinctTableJoin('marker_id','map_table','map_marker_link_table',$database_id,$field_list,$search_term,$search_mode,'all');
                            if (!is_array($marker_id_array))
                              {
                                $date = date('Y-m-d H:i:s');
                                echo "Error #97:$date<br>\n";
                                echo "Error in call to distinctTableJoin from individual_search.php<br>\n";
                                echo "$marker_id_array<br>\n";
                                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
                              }#end error in call to distinctTableJoin
                            if (sizeof($marker_id_array) == '0')
                              {
                                echo "<center>\n";
		                echo "Your search of the Map Table did not yield any individuals.<br>\n";
		                echo "Please try a new search with different search criteria.<br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
                              }#end if no records
                          }#end else map table field
                      }#end if only one search field
                    else #more than one search field
                      {
                        $final_query_field_list = array();
                        $final_query_term_array = array();
                        $final_query_mode_array = array();
                        $marker_table_field_list = array();
                        $marker_table_term_array = array();
                        $marker_table_mode_array = array();
                        $map_table_field_list    = array();
                        $map_table_term_array    = array();
                        $map_table_mode_array    = array();
                        $num_of_fields = sizeof($field_list);
                        $num_of_modes  = sizeof($mode);
                        for ($i = '0'; $i < $num_of_fields; $i++)
                          {
                            if (($field_list[$i] == 'marker_name') or ($field_list[$i] == 'chromosome'))
                              {
                                $place_on_field_list = ($i + 1);
                                $marker_table_field_list[] = $field_list[$i];
                                $num_of_mode_seen = '0';
                                for ($j='0'; $j<$num_of_modes; $j++)
                                  {
                                    if ($mode[$j] != 'Select Type of Search')
                                      {
                                        $num_of_mode_seen = ($num_of_mode_seen + 1);
                                        if ($place_on_field_list == $num_of_mode_seen)
                                          {
                                            $marker_table_term_array[] = $term[$j];
                                            $marker_table_mode_array[] = $mode[$j];
                                          }#end if right place on list
                                      }#end if real mode
                                  }#end foreach mode
                              }#end if marker table field
                            else #map table field
                              {
                                $place_on_field_list = ($i + 1);
                                $map_table_field_list[] = $field_list[$i];
                                $num_of_mode_seen = '0';
                                for ($j='0'; $j<$num_of_modes; $j++)
                                  {
                                    if ($mode[$j] != 'Select Type of Search')
                                      {
                                        $num_of_mode_seen = ($num_of_mode_seen + 1);
                                        if ($place_on_field_list == $num_of_mode_seen)
                                          {
                                            $map_table_term_array[] = $term[$j];
                                            $map_table_mode_array[] = $mode[$j];
                                          }#end if right place on list
                                      }#end if real mode
                                  }#end foreach mode
                              }#end else map table field
                          }#end for each field

                        if (sizeof($marker_table_field_list) > '0')
                          {
                            $marker_id_array = distinctCompoundTableQuery('marker_id','marker_table',$database_id,$marker_table_field_list,$marker_table_term_array,$marker_table_mode_array,$join,'all');
                            if (!is_array($marker_id_array))
                              {
                                $date = date('Y-m-d H:i:s');
                                echo "Error #98:$date<br>\n";
                                echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
                                echo "$marker_id_array<br>\n";
                                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
                              }#end error in call to distinctCompoundTableQuery
                            if (sizeof($marker_id_array) == '0')
                              {
                                if ($join == 'and')
                                  {
                                    echo "<center>\n";
		                    echo "Your search of the Map Table did not yield any individuals.<br>\n";
		                    echo "Please try a new search with different search criteria.<br>\n";
				    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                    echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                    echo "</center>\n";
		                    echo "</form>\n";
		                    echo "</body></html>\n";
		                    $ret_val = disconnect();
		                    exit;
                                  }#end if join == and
                              }#end if no records
                            else #have records
                              {
                                $marker_id_term = join($marker_id_array,',');
                                $final_query_field_list[] = 'marker_id';
                                $final_query_term_array[] = $marker_id_term;
                                $final_query_mode_array[] = 'in';
                                unset($marker_id_array);
                                unset($marker_id_term);
                              }#end else have records
                          }#end if have marker table fields
                        if (sizeof($map_table_field_list) > '0')
                          {
                            $map_id_array = distinctCompoundTableQuery('map_id','map_table',$database_id,$map_table_field_list,$map_table_term_array,$map_table_mode_array,$join,'all');
                            if (!is_array($map_id_array))
                              {
                                $date = date('Y-m-d H:i:s');
                                echo "Error #99:$date<br>\n";
                                echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
                                echo "$map_id_array<br>\n";
                                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
                              }#end error in call to distinctCompoundTableQuery
                            if (sizeof($map_id_array) == '0')
                              {
                                if ($join == 'and')
                                  {
                                    echo "<center>\n";
		                    echo "Your search of the Map Table did not yield any individuals.<br>\n";
		                    echo "Please try a new search with different search criteria.<br>\n";
				    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                    echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                    echo "</center>\n";
		                    echo "</form>\n";
		                    echo "</body></html>\n";
		                    $ret_val = disconnect();
		                    exit;
                                  }#end if join == and
                              }#end if no records
                            else #have records
                              {
                                $map_id_term = join($map_id_array,',');
                                $final_query_field_list[] = 'map_id';
                                $final_query_term_array[] = $map_id_term;
                                $final_query_mode_array[] = 'in';
                                unset($map_id_array);
                                unset($map_id_term);
                              }#end else have records
                          }#end if have map table fields

                        $marker_id_array = distinctCompoundTableQuery('marker_id','map_marker_link_table',$database_id,$final_query_field_list,$final_query_term_array,$final_query_mode_array,$join,'all');
                        if (!is_array($marker_id_array))
                          {
                            $date = date('Y-m-d H:i:s');
                            echo "Error #100:$date<br>\n";
                            echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
                            echo "$marker_id_array<br>\n";
                            echo "Please email the above error using The Comments/Help/Support link on the \n";
		            echo "left navigation bar.\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
                          }#end error in call to distinctCompoundTableQuery
                        if (sizeof($marker_id_array) == '0')
                          {
                            echo "<center>\n";
		            echo "Your search of the Map Table did not yield any individuals.<br>\n";
		            echo "Please try a new search with different search criteria.<br>\n";
			    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		            echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                            echo "</center>\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
                          }#end if no records
                      }#end else more than one search field
                    $marker_id_term = join($marker_id_array,',');
                    unset($marker_id_array);

                    $field_list_array = array('marker_id');
                    $indiv_table_id_array = distinctTableQuery('individual_table_id','genotype_table',$database_id,$field_list_array,$marker_id_term,'in','all');
                    if (!is_array($indiv_table_id_array))
                      {
                        $date = date('Y-m-d H:i:s');
                        echo "Error #101: $date<br>\n";
                        echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
                        echo "$indiv_table_id_array<br><br>\n";
                        echo "Please email the above error using The Comments/Help/Support link on the \n";
		        echo "left navigation bar.\n";
		        echo "</form>\n";
		        echo "</body></html>\n";
		        $ret_val = disconnect();
		        exit;
                      }#end error in call to distinctTableQuery
                    if (sizeof($indiv_table_id_array) == '0')
                      {
                        echo "<center>\n";
		        echo "Your search of the Map Table did not yield any individuals.<br>\n";
		        echo "Please try a new search with different search criteria.<br>\n";
			echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		        echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                        echo "</center>\n";
		        echo "</form>\n";
		        echo "</body></html>\n";
		        $ret_val = disconnect();
		        exit;
                      }#end if no records
                    $indiv_table_id_term = join($indiv_table_id_array,',');
                    unset($indiv_table_id_array);

                    $field_list_array = array('individual_table_id');
                    $num_indivs = countTableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in');
                    if (!preg_match('/^\d+$/',$num_indivs))
                      {
                        $date = date('Y-m-d H:i:s');
                        echo "Error #102: $date<br>\n";
                        echo "Error in call to countTableQuery from individual_search.php<br>\n";
                        echo "$num_indivs<br><br>\n";
                        echo "Please email the above error using The Comments/Help/Support link on the \n";
		        echo "left navigation bar.\n";
		        echo "</form>\n";
		        echo "</body></html>\n";
		        $ret_val = disconnect();
		        exit;
                      }#end error in call to countTableQuery
                    if ($num_indivs == '0')
                      {
                        echo "<center>\n";
		        echo "Your search of the Map Table did not yield any individuals.<br>\n";
		        echo "Please try a new search with different search criteria.<br>\n";
			echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		        echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                        echo "</center>\n";
		        echo "</form>\n";
		        echo "</body></html>\n";
		        $ret_val = disconnect();
		        exit;
                      }#end if no records

                    if ($num_indivs > (5 * $max_records_to_print_per_page))
                      {
                        if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                        if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                        $indiv_table_id_array = distinctTableQuery('individual_table_id','individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in','all',$order_by);
                        if (!is_array($indiv_table_id_array))
                          {
                            $date = date('Y-m-d H:i:s');
			    echo "Error #103: $date<br>\n";
			    echo "Error in call to distincTableQuery from individual_search.php<br>\n";
			    echo "$indiv_table_id_array<br><br>\n";
			    echo "Please email the above error using the Comments/Help/Support link on the \n";
			    echo "left navigation bar.\n";
			    echo "</form>\n";
			    echo "</body></html>\n";
			    $ret_val = disconnect();
			    exit;
			  }#end if error call to distinctTableQuery
                        $all_indiv_table_id_term = join($indiv_table_id_array,',');
                        unset($indiv_table_id_array);

                        moreThanFivePages($all_indiv_table_id_term);
                        unset($all_indiv_table_id_term);
                      }#end if more than five pages of records

                    if ($num_indivs > $max_records_to_print_per_page)
                      {
                        $indiv_multiple_pages = 1;
                        $from                 = "0";
                        $to                   = $max_records_to_print_per_page - 1;
                        $range                = "$from"."-"."$to";
                        if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                        if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                        $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in',$range,$order_by);
                        if (!is_array($indiv_rec_list))
                          {
                            $date = date('Y-m-d H:i:s');
                            echo "Error #104: $date<br>\n";
                            echo "Error in call to tableQuery from individual_search.php<br>\n";
                            echo "$indiv_rec_list<br><br>\n";
                            echo "Please email the above error using The Comments/Help/Support link on the \n";
		            echo "left navigation bar.\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
                          }#end error in call to tableQuery
                        $final_function_call   = 'tableQuery';
                        $final_table_name      = 'individual_table';
                        $final_field_list      = $field_list_array;
                        $final_term            = $indiv_table_id_term;
                        $final_mode            = 'in';
                        $final_order_by        = $order_by;
                        $last_record_retrieved = $max_records_to_print_per_page;
                      }#end if multiple pages
                    else #only a single page
                      {
                        $indiv_multiple_pages = 0;
                        $range                = "all";
                        if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                        if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                        $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in',$range,$order_by);
                        if (!is_array($indiv_rec_list))
                          {
                            $date = date('Y-m-d H:i:s');
                            echo "Error #105: $date<br>\n";
                            echo "Error in call to tableQuery from individual_search.php<br>\n";
                            echo "$indiv_rec_list<br><br>\n";
                            echo "Please email the above error using The Comments/Help/Support link on the \n";
		            echo "left navigation bar.\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
                          }#end error in call to tableQuery
                      }#end else only a single page 
                   }#end if (table_name == 'map_table')

		  elseif ($table_name == 'genotype_table')
                   {
                    if (sizeof($field_list) == '1')
                      {
                        $final_query_field_list = array();
                        $final_query_search_term = "";
                        $final_query_search_mode = "";
                        $num_of_modes = sizeof($mode);
                        for ($i = '0'; $i < $num_of_modes; $i++)
                          {
                            if ($mode[$i] != 'Select Type of Search')
                              {
                                $search_term = $term[$i];
                                $search_mode = $mode[$i];
                              }
                          }#end determine which term and mode to use

                        if (($field_list[0] == 'individual_id') or ($field_list[0] == 'pedigree_id'))
                          {
                            $indiv_table_id_array = distinctTableQuery('individual_table_id','individual_table',$database_id,$field_list,$search_term,$search_mode,'all');
                            if (!is_array($indiv_table_id_array))
                              {
                                $date = date('Y-m-d H:i:s');
                                echo "Error #106: $date<br>\n";
                                echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
                                echo "$indiv_table_id_array<br>\n";
                                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
                              }#end error in call to distinctTableQuery
                            if (sizeof($indiv_table_id_array) == '0')
                              {
                                echo "<center>\n";
		                echo "Your search of the Genotype Table did not yield any individuals.<br>\n";
		                echo "Please try a new search with different search criteria.<br>\n";
				echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
                              }#end if sizeof(rec_list) == '0'
                            $indiv_table_id_term = join($indiv_table_id_array,',');
                            $final_query_field_list[] = 'individual_table_id';
                            $final_query_search_term  = $indiv_table_id_term;
                            $final_query_search_mode  = 'in';
			    unset($indiv_table_id_array);
                          }#end if individual_table fields
                        elseif (($field_list[0] == 'marker_name') or ($field_list[0] == 'chromosome'))
                          {
                            $marker_id_array = distinctTableQuery('marker_id','marker_table',$database_id,$field_list,$search_term,$search_mode,'all');
                            if (!is_array($marker_id_array))
                              {
                                $date = date('Y-m-d H:i:s');
                                echo "Error #107: $date<br>\n";
                                echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
                                echo "$marker_id_array<br><br>\n";
                                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
                              }#end error in call to distinctTableQuery
                            if (sizeof($marker_id_array) == '0')
                              {
                                echo "<center>\n";
		                echo "Your search of the Genotype Table did not yield any individuals.<br>\n";
		                echo "Please try a new search with different search criteria.<br>\n";
				echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
                              }#end if sizeof(rec_list) == '0'
                            $marker_id_term = join($marker_id_array,',');
                            $final_query_field_list[] = 'marker_id';
                            $final_query_search_term  = $marker_id_term;
                            $final_query_search_mode  = 'in';
			    unset($marker_id_array);
                          }
                        elseif (($field_list[0] == 'allele_1_code') or ($field_list[0] == 'allele_2_code'))
                          {
                            $field_list_array = array('allele_code');
                            $allele_id_array = distinctTableQuery('allele_id','allele_table',$database_id,$field_list_array,$search_term,$search_mode,'all');
                            if (!is_array($allele_id_array))
                              {
                                $date = date('Y-m-d H:i:s');
                                echo "Error #108: $date<br>\n";
                                echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
                                echo "$allele_id_array<br><br>\n";
                                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
                              }#end error in call to distinctTableQuery
                            if (sizeof($allele_id_array) == '0')
                              {
                                echo "<center>\n";
		                echo "Your search of the Genotype Table did not yield any individuals.<br>\n";
		                echo "Please try a new search with different search criteria.<br>\n";
				echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
                              }#end if sizeof(rec_list) == '0'
                            $allele_id_term = join($allele_id_array,',');
                            $final_query_field_list[] = 'allele_1_id';
                            $final_query_field_list[] = 'allele_2_id';
                            $final_query_search_term  = $allele_id_term;
                            $final_query_search_mode  = 'in';
			    unset($allele_id_array);
                          }
                        else #genotype table field
                          {
                            $final_query_field_list[] = $field_list[0];
                            $final_query_search_term  = $search_term;
                            $final_query_search_mode  = $search_mode;
                          }  
                           
		        $indiv_table_id_array = distinctTableQuery('individual_table_id',$table_name,$database_id,$final_query_field_list,$final_query_search_term,$final_query_search_mode,'all');
		        if (!is_array($indiv_table_id_array))
                          {
                            $date = date('Y-m-d H:i:s');
		            echo "Error #109: $date<br>\n";
		            echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
		            echo "$indiv_table_id_array<br><br>\n";
		            echo "Please email the above error using The Comments/Help/Support link on the \n";
		            echo "left navigation bar.\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
		          }#end if (!is_array(rec_list))
		        if (sizeof($indiv_table_id_array) == '0')
                          {
                            echo "<center>\n";
		            echo "Your search of the Genotype Table did not yield any individuals.<br>\n";
		            echo "Please try a new search with different search criteria.<br>\n";
			    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		            echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                            echo "</center>\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
		          }#end if (sizeof(rec_list) == '0')
		        $indiv_table_id_term = join($indiv_table_id_term,'0');
			unset($indiv_table_id_array);

		        $field_list_array = array('individual_table_id');
			$num_of_indivs = countTableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in');
			if (!preg_match('/^\d+$/',$num_of_indivs))
                          {
                            $date = date('Y-m-d H:i:s');
                            echo "Error #110: $date<br>\n";
			    echo "Error in call to countTableQuery from individual_search.php<br>\n";
			    echo "$num_of_indivs<br><br>\n";
			    echo "Please email the above error using the Comments/Help/Support link on the \n";
			    echo "left navigation bar.\n";
			    echo "</form>\n";
			    echo "</body></html>\n";
			    $ret_val = disconnect();
			    exit;
		          }#end error in call to countTableQuery

                        #if ($num_of_indivs > $max_records_to_print)
                        #  {
                        #    echo "Your search returned $num_of_indivs individuals.<br>\n";
                        #    tooManyIndividuals($indiv_table_id_term);
                        #    $ret_val = disconnect();
                        #    exit;
                        #  }#end if more than max records

		        if ($num_of_indivs > ($max_records_to_print_per_page * 5))
                          {
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                            $indiv_table_id_array = distinctTableQuery('individual_table_id','individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in','all',$order_by);
                            if (!is_array($indiv_table_id_array))
                              {
                                $date = date('Y-m-d H:i:s');
			        echo "Error #111: $date<br>\n";
			        echo "Error in call to distincTableQuery from individual_search.php<br>\n";
			        echo "$indiv_table_id_array<br><br>\n";
			        echo "Please email the above error using the Comments/Help/Support link on the \n";
			        echo "left navigation bar.\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if error call to distinctTableQuery
                            $all_indiv_table_id_term = join($indiv_table_id_array,',');
                            unset($indiv_table_id_array);

                            moreThanFivePages($all_indiv_table_id_term);
                            unset($all_indiv_table_id_term);
                          }#end if more than 5 pages returned

		        if ($num_of_indivs > $max_records_to_print_per_page)
		          {
			    $indiv_multiple_pages = 1;
                            $from                 = "0";
                            $to                   = $max_records_to_print_per_page - 1;
                            $range                = "$from"."-"."$to";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
			    $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in',$range,$order_by);
			    if (!is_array($indiv_rec_list))
			      {
			        $date = date('Y-m-d H:i:s');
			        echo "Error #112: $date<br>\n";
			        echo "Error in call to tableQuery from individual_search.php<br>\n";
			        echo "$indiv_rec_list<br><br>\n";
			        echo "Please email the above error using the Comments/Help/Support link on the \n";
			        echo "left navigation bar.\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if (!is_array(indiv_rec_list))
                            if (sizeof($indiv_rec_list) == '0')
			      {
			        echo "<center>\n";
			        echo "Your search of the Marker Table did not yield any individuals.<br>\n";
			        echo "Please try your search again with different search criteria.<br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
			        echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
			        echo "</center>\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if (sizeof(indiv_rec_list) == '0')
			    $final_function_call   = 'tableQuery';
			    $final_table_name      = 'individual_table';
			    $final_field_list      = $field_list_array;
			    $final_term            = $indiv_table_id_term;
			    $final_mode            = 'in';
			    $final_order_by        = $order_by;
                            $last_record_retrieved = $max_records_to_print_per_page;
                          }#end if more than a one page
                        else #only a single page
		          {
			    $indiv_multiple_pages = 0;
                            $range                = "all";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
		            $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in',$range,$order_by);
		            if (!is_array($indiv_rec_list))
                              {
                                $date = date('Y-m-d H:i:s');
		                echo "Error #113: $date<br>\n";
		                echo "Error in call to tableQuery from individual_search.php<br>\n";
		                echo "$indiv_rec_list<br><br>\n";
		                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (!is_array(indiv_rec_list))
		            if (sizeof($indiv_rec_list) == '0')
                              {
                                echo "<center>\n";
		                echo "Your search of the Genotype Table did not yield any individuals.<br>\n";
		                echo "Please try a new search with different search criteria.<br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (sizeof(indiv_rec_list) == '0')
			  }#end else only a single page
                      }#end if sizeof(field_list) == '1'
                    else #sizeof(field_list) > '1'
                      {
                        $individual_table_field_list = array();
                        $individual_table_term_array = array();
                        $individual_table_mode_array = array();
                        $marker_table_field_list     = array();
                        $marker_table_term_array     = array();
                        $marker_table_mode_array     = array();
                        $allele_table_field_list     = array();
                        $allele_table_term_array     = array();
                        $allele_table_mode_array     = array();
                        $final_query_field_list      = array();
                        $final_query_term_array      = array();
                        $final_query_mode_array      = array();
                        $num_of_fields = sizeof($field_list);
                        $num_of_modes  = sizeof($mode);
                        for ($i = '0'; $i < $num_of_fields; $i++)
                          {
                            if (($field_list[$i] == 'individual_id') or ($field_list[$i] == 'pedigree_id'))
                              {
                                $place_on_field_list = ($i + 1);
                                $individual_table_field_list[] = $field_list[$i];
                                $num_of_mode_seen = '0';
                                for ($j='0'; $j<$num_of_modes; $j++)
                                  {
                                    if ($mode[$j] != 'Select Type of Search')
                                      {
                                        $num_of_mode_seen = ($num_of_mode_seen + 1);
                                        if ($place_on_field_list == $num_of_mode_seen)
                                          {
                                            $individual_table_term_array[] = $term[$j];
                                            $individual_table_mode_array[] = $mode[$j];
                                          }#end if right place on list
                                      }#end if real mode
                                  }#end foreach mode
                              }
                            elseif (($field_list[$i] == 'marker_name') or ($field_list[$i] == 'chromosome'))
                              {
                                $place_on_field_list = ($i + 1);
                                $marker_table_field_list[] = $field_list[$i];
                                $num_of_mode_seen = '0';
                                for ($j='0'; $j<$num_of_modes; $j++)
                                  {
                                    if ($mode[$j] != 'Select Type of Search')
                                      {
                                        $num_of_mode_seen = ($num_of_mode_seen + 1);
                                        if ($place_on_field_list == $num_of_mode_seen)
                                          {
                                            $marker_table_term_array[]  = $term[$j];
                                            $marker_table_mode_array[]  = $mode[$j];
                                          }#end if right place on list
                                      }#end if real mode
                                  }#end foreach mode
                              }
                            elseif (($field_list[$i] == 'allele_1_code') or ($field_list[$i] == 'allele_2_code'))
                              {
                                $place_on_field_list = ($i + 1);
                                $allele_table_field_list[] = 'allele_code';
                                $num_of_mode_seen = '0';
                                for ($j='0'; $j<$num_of_modes; $j++)
                                  {
                                    if ($mode[$j] != 'Select Type of Search')
                                      {
                                        $num_of_mode_seen = ($num_of_mode_seen + 1);
                                        if ($place_on_field_list == $num_of_mode_seen)
                                          {
                                            $allele_table_term_array[] = $term[$j];
                                            $allele_table_mode_array[] = $mode[$j];
                                          }#end if right place on list
                                      }#end if real mode
                                  }#end foreach mode
                              }
                            else
                              {
                                $place_on_field_list = ($i + 1);
                                $final_query_field_list[] = $field_list[$i];
                                $num_of_mode_seen = '0';
                                for ($j='0'; $j<$num_of_modes; $j++)
                                  {
                                    if ($mode[$j] != 'Select Type of Search')
                                      {
                                        $num_of_mode_seen = ($num_of_mode_seen + 1);
                                        if ($place_on_field_list == $num_of_mode_seen)
                                          {
                                            $final_query_term_array[] = $term[$j];
                                            $final_query_mode_array[] = $mode[$j];
                                          }#end if right place on list
                                      }#end if real mode
                                  }#end foreach mode
                              }
                          }#end for each field

                        if (sizeof($individual_table_field_list) > '0')
                          {
                            if (sizeof($individual_table_field_list) > '1')
                              {
                                $indiv_table_id_array = distinctCompoundTableQuery('individual_table_id','individual_table',$database_id,$individual_table_field_list,$individual_table_term_array,$individual_table_mode_array,$join,'all');
                                if (!is_array($indiv_table_id_array))
                                  {
                                    $date = date('Y-m-d H:i:s');
                                    echo "Error #114: $date<br>\n";
                                    echo "Error in call to compoundTableQuery from individual_search.php<br>\n";
                                    echo "$indiv_table_id_array<br><br>\n";
                                    echo "Please email the above error using The Comments/Help/Support link on the \n";;;;
		                    echo "left navigation bar.\n";
		                    echo "</form>\n";
		                    echo "</body></html>\n";
		                    $ret_val = disconnect();
		                    exit;
                                  }#end error in call to compoundTableQuery
                                if (sizeof($indiv_table_id_array) > '0')
                                  {
                                    $indiv_table_id_term = join($indiv_table_id_array,',');
                                    $final_query_field_list[] = 'individual_table_id';
                                    $final_query_term_array[] = $indiv_table_id_term;
                                    $final_query_mode_array[] = 'in';
				    unset($indiv_table_id_array);
                                  }#end if have individuals
                                else #no records
                                  {
                                    if ($join == 'and')
                                      {
                                        echo "<center>\n";
		                        echo "Your search of the Genotype Table did not yield any individuals.<br>\n";
		                        echo "Please try a new search with different search criteria.<br>\n";
					echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                        echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                        echo "</center>\n";
		                        echo "</form>\n";
		                        echo "</body></html>\n";
		                        $ret_val = disconnect();
		                        exit;
                                      }#end if join == and
                                  }#end else no records
                              }#end if have more than one individual table field
                            else #only have one individual table field
                              {
                                $indiv_table_id_array = distinctTableQuery('individual_table_id','individual_table',$database_id,$individual_table_field_list,$individual_table_term_array[0],$individual_table_mode_array[0],'all');
                                if (!is_array($indiv_table_id_array))
                                  {
                                    $date = date('Y-m-d H:i:s');
                                    echo "Error #115: $date<br>\n";
                                    echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
                                    echo "$indiv_table_id_array<br><br>\n";
                                    echo "Please email the above error using The Comments/Help/Support link on the \n";;;;
		                    echo "left navigation bar.\n";
		                    echo "</form>\n";
		                    echo "</body></html>\n";
		                    $ret_val = disconnect();
		                    exit;
                                  }#end error in call to distinctTableQuery
                                if (sizeof($indiv_table_id_array) > '0')
                                  {
                                    $indiv_table_id_term = join($indiv_table_id_array,',');
                                    $final_query_field_list[] = 'individual_table_id';
                                    $final_query_term_array[] = $indiv_table_id_term;
                                    $final_query_mode_array[] = 'in';
				    unset($indiv_table_id_array);
                                  }
                                else #no records
                                  {
                                    if ($join == 'and')
                                      {
                                        echo "<center>\n";
		                        echo "Your search of the Genotype Table did not yield any individuals.<br>\n";
		                        echo "Please try a new search with different search criteria.<br>\n";
					echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                        echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                        echo "</center>\n";
		                        echo "</form>\n";
		                        echo "</body></html>\n";
		                        $ret_val = disconnect();
		                        exit;
                                      }#end if join == and
                                  }#end else no records
                              }#end else only one individual table field
                          }#end if have individual table fields
                        
                        if (sizeof($marker_table_field_list) > '0')
                          {
                            if (sizeof($marker_table_field_list) > 1)
                              {
                                $marker_id_array = distinctCompoundTableQuery('marker_id','marker_table',$database_id,$marker_table_field_list,$marker_table_term_array,$marker_table_mode_array,$join,'all');
                                if (!is_array($marker_id_array))
                                  {
                                    $date = date('Y-m-d H:i:s');
                                    echo "Error #116: $date<br>\n";
                                    echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
                                    echo "$marker_id_array<br><br>\n";
                                    echo "Please email the above error using The Comments/Help/Support link on the \n";;;;
		                    echo "left navigation bar.\n";
		                    echo "</form>\n";
		                    echo "</body></html>\n";
		                    $ret_val = disconnect();
		                    exit;
                                  }#end error in call to distinctCompoundTableQuery
                              }#end if more than one marker table field
                            else #only one marker table field
                              {
                                $marker_id_array = distinctTableQuery('marker_id','marker_table',$database_id,$marker_table_field_list,$marker_table_term_array[0],$marker_table_mode_array[0],'all');
                                if (!is_array($marker_id_array))
                                  {
                                    $date = date('Y-m-d H:i:s');
                                    echo "Error #117: $date<br>\n";
                                    echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
                                    echo "$marker_id_array<br><br>\n";
                                    echo "Please email the above error using The Comments/Help/Support link on the \n";;;;
		                    echo "left navigation bar.\n";
		                    echo "</form>\n";
		                    echo "</body></html>\n";
		                    $ret_val = disconnect();
		                    exit;
                                  }#end error in call to distinctTableQuery
                              }#end else only one marker table field
                            if (sizeof($marker_id_array) > '0')
                              {
                                $marker_id_term = join($marker_id_array,',');
                                $final_query_field_list[] = 'marker_id';
                                $final_query_term_array[] = $marker_id_term;
                                $final_query_mode_array[] = 'in';
				unset($marker_id_array);
                              }#end if have marker_ids
                            else #no records
                              {
                                if ($join == 'and')
                                  {
                                    echo "<center>\n";
		                    echo "Your search of the Genotype Table did not yield any individuals.<br>\n";
		                    echo "Please try a new search with different search criteria.<br>\n";
				    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                    echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                    echo "</center>\n";
		                    echo "</form>\n";
		                    echo "</body></html>\n";
		                    $ret_val = disconnect();
		                    exit;
                                  }#end if join == and
                              }#end else no records
                          }#end if have marker_table field

                        if (sizeof($allele_table_field_list) > '0')
                          {
                            if (sizeof($allele_table_field_list) > '1')
                              {
                                $allele_1_field_list = array($allele_table_field_list[0]);
                                $allele_1_id_array = distinctTableQuery('allele_id','allele_table',$database_id,$allele_1_field_list,$allele_table_term[0],$allele_table_mode_array[0],'all');
                                if (!is_array($allele_1_id_array))
                                  {
                                    $date = date('Y-m-d H:i:s');
                                    echo "Error #118: $date<br>\n";
                                    echo "Error in call to discintCompoundTableQuery from individual_search.php<br>\n";
                                    echo "$allele_1_id_array<br><br>\n";
                                    echo "Please email the above error using The Comments/Help/Support link on the \n";;;;
		                    echo "left navigation bar.\n";
		                    echo "</form>\n";
		                    echo "</body></html>\n";
		                    $ret_val = disconnect();
		                    exit;
                                  }
                                
                                $allele_2_field_list = array($allele_table_field_list[1]);
                                $allele_2_id_array = distinctTableQuery('allele_id','allele_table',$database_id,$allele_1_field_list,$allele_table_term[1],$allele_table_mode_array[1],'all');
                                if (!is_array($allele_2_id_array))
                                  {
                                    $date = date('Y-m-d H:i:s');
                                    echo "Error #119: $date<br>\n";
                                    echo "Error in call to discintCompoundTableQuery from individual_search.php<br>\n";
                                    echo "$allele_2_id_array<br><br>\n";
                                    echo "Please email the above error using The Comments/Help/Support link on the \n";;;;
		                    echo "left navigation bar.\n";
		                    echo "</form>\n";
		                    echo "</body></html>\n";
		                    $ret_val = disconnect();
		                    exit;
                                  }

                                if ((sizeof($allele_1_id_array) > 0) and (sizeof($allele_2_id_array) > 0))
                                  {
                                    $allele_1_id_term = join($allele_1_id_array,',');
                                    $allele_2_id_term = join($allele_2_id_array,',');
                                    unset($allele_1_id_array,$allele_2_id_array);

                                    $genotype_id_array = array();
                                    $field_list_array = array('allele_1_id','allele_2_id');
                                    $term_array       = array($allele_1_id_term,$allele_2_id_term);
                                    $mode_array       = array('in','in');
                                    $genotype_ids = distinctCompoundTableQuery('genotype_id','genotype_table',$database_id,$field_list_array,$term_array,$mode_array,$join,'all');
                                    if (!is_array($genotype_ids))
                                      {
                                        $date = date('Y-m-d H:i:s');
                                        echo "Error #120: $date<br>\n";
                                        echo "Error in call to discintCompoundTableQuery from individual_search.php<br>\n";
                                        echo "$genotype_ids<br><br>\n";
                                        echo "Please email the above error using The Comments/Help/Support link on the \n";;;;
		                        echo "left navigation bar.\n";
		                        echo "</form>\n";
		                        echo "</body></html>\n";
		                        $ret_val = disconnect();
		                        exit;
                                      }#end error in call to distinctCompoundTableQuery
				    $genotype_id_array = $genotype_ids;
				    unset($genotype_ids);

                                    $term_array = array($allele_2_id_term,$allele_1_id_term);
                                    $genotype_ids = distinctCompoundTableQuery('genotype_id','genotype_table',$database_id,$field_list_array,$term_array,$mode_array,$join,'all');
                                    if (!is_array($genotype_ids))
                                      {
                                        $date = date('Y-m-d H:i:s');
                                        echo "Error #121: $date<br>\n";
                                        echo "Error in call to discintCompoundTableQuery from individual_search.php<br>\n";
                                        echo "$genotype_ids<br><br>\n";
                                        echo "Please email the above error using The Comments/Help/Support link on the \n";;;;
		                        echo "left navigation bar.\n";
		                        echo "</form>\n";
		                        echo "</body></html>\n";
		                        $ret_val = disconnect();
		                        exit;
                                      }#end error in call to distinctCompoundTableQuery
				    foreach ($genotype_ids as $genotype_id){if (!in_array($genotype_id,$genotype_id_array)){$genotype_id_array[] = $genotype_id;}}
				    unset($genotype_ids);

                                    if (sizeof($genotype_id_array) > 0)
                                      {
					$genotype_id_term = join($genotype_id_array,',');
                                        $final_query_field_list[] = 'genotype_id';
                                        $final_query_term_array[] = $genotype_id_term;
                                        $final_query_mode_array[] = 'in';
                                        unset($genotype_id_array);
				      }#end if have genotypes
				    else #no genotypes match criteria
				      {
					if ($join == 'and')
                                          {
                                            echo "<center>\n";
		                            echo "Your search of the Genotype Table did not yield any individuals.<br>\n";
		                            echo "Please try a new search with different search criteria.<br>\n";
					    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                            echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                            echo "</center>\n";
		                            echo "</form>\n";
		                            echo "</body></html>\n";
		                            $ret_val = disconnect();
		                            exit;
                                          }#end if join == and
                                      }#end else no records
				  }#end if allele_1_id_array and allele_2_id_array have ids
				else #not both of the allele id arrays have ids
				  {
				    if ($join == 'and')
				      {
					echo "<center>\n";
					echo "Your search of the Genotype Table did not yield any individuals.<br>\n";
					echo "Please try a new search with different search criteria.<br>\n";
					echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
					echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
					echo "</center>\n";
					echo "</form>\n";
					echo "</body></html>\n";
					$ret_val = disconnect();
					exit;
				      }#end if join == and
				    else #join == or
				      {
					$field_list_array = array('allele_1_id','allele_2_id');
                                        if (sizeof($allele_1_id_array) > 0) {$term = join($allele_1_id_array,',');}
					if (sizeof($allele_2_id_array) > 0) {$term = join($allele_2_id_array,',');}
					$mode = 'in';
					$genotype_id_array = distinctTableQuery('genotype_id','genotype_table',$database_id,$field_list_array,$term,$mode,'all');
					if (!is_array($genotype_id_array))
					  {
					    $date = date('Y-m-d H:i:s');
					    echo "Error #122: $date<br>\n";
					    echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
					    echo "$genotype_id_array<br><br>\n";
					    echo "Please email the above error using The Comments/Help/Support link on the \n";;;;
					    echo "left navigation bar.\n";
					    echo "</form>\n";
					    echo "</body></html>\n";
					    $ret_val = disconnect();
					    exit;
					  }#end error in call to distinctTableQuery
					if (sizeof($genotype_id_array) > 0)
					  {
					    $genotype_id_term = join($genotype_id_array,',');
					    $final_field_list[] = 'genotype_id';
					    $final_term_array[] = $genotype_id_term;
					    $final_mode_array[] = 'in';
					    unset($genotype_id_array);
					  }#end if have ids
                                      }#end else join == or
				  }#end else both allele id arrays don't have ids
                              }#end if have more than one field
                            else #only have one field
                              {
                                $allele_id_array = distinctTableQuery('allele_id','allele_table',$database_id,$allele_table_field_list,$allele_table_term_array[0],$allele_table_mode_array[0],'all');
                                if (!is_array($allele_id_array))
                                  {
				    $date = date('Y-m-d H:i:s');
                                    echo "Error #123: $date<br>\n";
                                    echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
                                    echo "$allele_id_array<br><br>\n";
                                    echo "Please email the above error using The Comments/Help/Support link on the \n";;;;
		                    echo "left navigation bar.\n";
		                    echo "</form>\n";
		                    echo "</body></html>\n";
		                    $ret_val = disconnect();
		                    exit;
                                  }#end error in call to distinctTableQuery
                                if (sizeof($allele_id_array) > '0')
                                  {
                                    $allele_id_term = join($allele_id_array,',');
                                    $field_list_array = array('allele_1_id','allele_2_id');
                                    $genotype_id_array = distinctTableQuery('genotype_id','genotype_table',$database_id,$field_list_array,$allele_id_term,'in','all');
                                    if (!is_array($genotype_id_array))
                                      {
					$date = date('Y-m-d H:i:s');
                                        echo "Error #124: $date<br>\n";
                                        echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
                                        echo "$genotype_id_array<br><br>\n";
                                        echo "Please email the above error using The Comments/Help/Support link on the \n";;;;
		                        echo "left navigation bar.\n";
		                        echo "</form>\n";
		                        echo "</body></html>\n";
		                        $ret_val = disconnect();
		                        exit;
                                      }#end error in call to distinctTableQuery
                                    if (sizeof($genotype_id_array) > '0')
                                      {
                                        $genotype_id_term = join($genotype_id_array,',');
                                        $final_query_field_list[] = 'genotype_id';
                                        $final_query_term_array[] = $genotype_id_term;
                                        $final_query_mode_array[] = 'in';
					unset($genotype_id_array);
                                      }#end if have records
                                    else #no records
                                      {
                                        if ($join == 'and')
                                          {
                                            echo "<center>\n";
		                            echo "Your search of the Genotype Table did not yield any individuals.<br>\n";
		                            echo "Please try a new search with different search criteria.<br>\n";
					    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                            echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                            echo "</center>\n";
		                            echo "</form>\n";
		                            echo "</body></html>\n";
		                            $ret_val = disconnect();
		                            exit;
                                          }#end if join == and
                                      }#end else no records
                                  }#end if have records
                                else #no allele ids
                                  {
                                    if ($join == 'and')
                                      {
                                        echo "<center>\n";
		                        echo "Your search of the Genotype Table did not yield any individuals.<br>\n";
		                        echo "Please try a new search with different search criteria.<br>\n";
					echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                        echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                        echo "</center>\n";
		                        echo "</form>\n";
		                        echo "</body></html>\n";
		                        $ret_val = disconnect();
		                        exit;
                                      }#end if join == and
                                  }#end else no records
                                unset($allele_id_array);
                              }#end else only one field
                          }#end if have allele table fields

                        $indiv_table_id_array = distinctCompoundTableQuery('individual_table_id',$table_name,$database_id,$final_query_field_list,$final_query_term_array,$final_query_mode_array,$join,'all');
                        if (!is_array($individual_table_id_array))
                          {
			    $date = date('Y-m-d H:i:s');
                            echo "Error #125: $date<br>\n";
                            echo "Error in call to compoundTableQuery from individual_search.php<br>\n";
                            echo "$indiv_table_id_array<br><br>\n";
                            echo "Please email the above error using The Comments/Help/Support link on the \n";
		            echo "left navigation bar.\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
                          }#end error in call to compoundTableQuery
                        if (sizeof($indiv_table_id_array) == '0')
                          {
                            echo "<center>\n";
		            echo "Your search of the Genotype Table did not yield any individuals.<br>\n";
		            echo "Please try a new search with different search criteria.<br>\n";
			    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		            echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                            echo "</center>\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
                          }#end if sizeof(rec_list) == '0'
                        $indiv_table_id_term = join($indiv_table_id_array,',');
			unset($indiv_table_id_array);
                        
                        $field_list_array = array('individual_table_id');
			$num_of_indivs = countTableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in');
			if (!preg_match('/^\d+$/',$num_of_indivs))
                          {
                            $date = date('Y-m-d H:i:s');
                            echo "Error #126: $date<br>\n";
			    echo "Error in call to countTableQuery from individual_search.php<br>\n";
			    echo "$num_of_indivs<br><br>\n";
			    echo "Please email the above error using the Comments/Help/Support link on the \n";
			    echo "left navigation bar.\n";
			    echo "</form>\n";
			    echo "</body></html>\n";
			    $ret_val = disconnect();
			    exit;
		          }#end error in call to countTableQuery

                        #if ($num_of_indivs > $max_records_to_print)
                        #  {
                        #    echo "Your search returned $num_of_indivs individuals.<br>\n";
                        #    tooManyIndividuals($indiv_table_id_term);
                        #    $ret_val = disconnect();
                        #    exit;
                        #  }#end if more than max to print

		        if ($num_of_indivs > ($max_records_to_print_per_page * 5))
                          {
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                            $indiv_table_id_array = distinctTableQuery('individual_table_id','individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in','all',$order_by);
                            if (!is_array($indiv_table_id_array))
                              {
                                $date = date('Y-m-d H:i:s');
			        echo "Error #127: $date<br>\n";
			        echo "Error in call to distincTableQuery from individual_search.php<br>\n";
			        echo "$indiv_table_id_array<br><br>\n";
			        echo "Please email the above error using the Comments/Help/Support link on the \n";
			        echo "left navigation bar.\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if error call to distinctTableQuery
                            $all_indiv_table_id_term = join($indiv_table_id_array,',');
                            unset($indiv_table_id_array);

                            moreThanFivePages($all_indiv_table_id_term);
                            unset($all_indiv_table_id_term);
                          }#end if more than 5 pages returned

		        if ($num_of_indivs > $max_records_to_print_per_page)
		          {
			    $indiv_multiple_pages = 1;
                            $from                 = "0";
                            $to                   = $max_records_to_print_per_page - 1;
                            $range                = "$from"."-"."$to";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
			    $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in',$range,$order_by);
			    if (!is_array($indiv_rec_list))
			      {
			        $date = date('Y-m-d H:i:s');
			        echo "Error #128: $date<br>\n";
			        echo "Error in call to tableQuery from individual_search.php<br>\n";
			        echo "$indiv_rec_list<br><br>\n";
			        echo "Please email the above error using the Comments/Help/Support link on the \n";
			        echo "left navigation bar.\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if (!is_array(indiv_rec_list))
                            if (sizeof($indiv_rec_list) == '0')
			      {
			        echo "<center>\n";
			        echo "Your search of the Marker Table did not yield any individuals.<br>\n";
			        echo "Please try your search again with different search criteria.<br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
			        echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
			        echo "</center>\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if (sizeof(indiv_rec_list) == '0')
			    $final_function_call   = 'tableQuery';
			    $final_table_name      = 'individual_table';
			    $final_field_list      = $field_list_array;
			    $final_term            = $indiv_table_id_term;
			    $final_mode            = 'in';
			    $final_order_by        = $order_by;
                            $last_record_retrieved = $max_records_to_print;
                          }#end if more than a single page
                        else #only a single page
		          {
			    $indiv_multiple_pages = 0;
                            $range                = "all";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                            $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in',$range,$order_by);
		            if (!is_array($indiv_rec_list))
                              {
			        $date = date('Y-m-d H:i:s');
		                echo "Error #129: $date<br>\n";
		                echo "Error in call to tableQuery from individual_search.php<br>\n";
		                echo "$indiv_rec_list<br><br>\n";
		                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (!is_array(indiv_rec_list))
		            if (sizeof($indiv_rec_list) == '0')
                              {
                                echo "<center>\n";
		                echo "Your search of the Genotype Table did not yield any individuals.<br>\n";
		                echo "Please try a new search with different search criteria.<br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (sizeof(indiv_rec_list) == '0')
			  }#end else only a single page
                      }#end else sizeof(field_list) > '1'
		   }#end if (table_name == 'genotype_table')

                 elseif ($table_name == 'allele_table')
                   {
                    if (sizeof($field_list) == '1')
                      {
                        $num_of_modes = sizeof($mode);
                        for ($i = '0'; $i < $num_of_modes; $i++)
                          {
                            if ($mode[$i] != 'Select Type of Search')
                              {
                                $search_term = $term[$i];
                                $search_mode = $mode[$i];
                              }
                          }#end determine which term and mode to use

                        if ($field_list[0] == 'marker_name')
                          {
                            $rec_list = distinctTableJoin('allele_id','marker_table',$table_name,$database_id,$field_list,$search_term,$search_mode,'all');
                            if (!is_array($rec_list))
                              {
				$date = date('Y-m-d H:i:s');
                                echo "Error #130: $date<br>\n";
                                echo "Error in call to distinctTableJoin from individual_search.php<br>\n";
                                echo "$rec_list<br><br>\n";
                                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
                              }#end error in call to distinctTableJoin
                            if (sizeof($rec_list) == '0')
                              {
                                echo "<center>\n";
		                echo "Your search of the Allele Table did yield any individuals.<br>\n";
		                echo "Please try a new search with different search criteria.<br>\n";
				echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
                              }#end if sizeof(rec_list) == '0'
                            $allele_id_term = join($rec_list,',');
			    unset($rec_list);
                          }#end if field is marker_name
                        else #field is in allele_table
                          {
                            $rec_list = distinctTableQuery('allele_id',$database_id,$table_name,$field_list,$search_term,$search_mode,'all');
                            if (!is_array($rec_list))
                              {
				$date = date('Y-m-d H:i:s');
                                echo "Error #131: $date<br>\n";
                                echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
                                echo "$rec_list<br><br>\n";
                                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (!is_array(rec_list))
		            if (sizeof($rec_list) == '0')
                              {
                                echo "<center>\n";
		                echo "Your search of the Allele Table did yield any individuals.<br>\n";
		                echo "Please try a new search with different search criteria.<br>\n";
				echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (sizeof(rec_list) == '0')
                            $allele_id_term = join($rec_list,',');
			    unset($rec_list);
                          }#end else field is in allele_table

                        $field_list_array = array('allele_1_id','allele_2_id');
                        $rec_list = distinctTableQuery('individual_table_id','genotype_table',$database_id,$field_list_array,$allele_id_term,'in','all');
                        if (!is_array($rec_list))
                          {
			    $date = date('Y-m-d H:i:s');
                            echo "Error #132: $date<br>\n";
                            echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
                            echo "$rec_list<br><br>\n";
                            echo "Please email the above error using The Comments/Help/Support link on the \n";
		            echo "left navigation bar.\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
		          }#end if error in call to distinctTableQuery
		        if (sizeof($rec_list) == '0')
                          {
                            echo "<center>\n";
		            echo "Your search of the Allele Table did yield any individuals.<br>\n";
		            echo "Please try a new search with different search criteria.<br>\n";
			    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		            echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                            echo "</center>\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
		          }#end if (sizeof(rec_list) == '0')
                        $indiv_table_id_term = join($rec_list,',');
                        unset($rec_list);

                        $field_list_array = array('individual_table_id');
                        $indiv_table_id_array = distinctTableQuery('individual_table_id','genotype_table',$database_id,$field_list_array,$indiv_table_id_term,'in','all');
                        if (!is_array($indiv_table_id_array))
                          {
			    $date = date('Y-m-d H:i:s');
                            echo "Error #133: $date<br>\n";
                            echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
                            echo "$indiv_table_id_array<br><br>\n";
                            echo "Please email the above error using The Comments/Help/Support link on the \n";
		            echo "left navigation bar.\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
		          }#end if (!is_array(rec_list))
		        if (sizeof($indiv_table_id_array) == '0')
                          {
                            echo "<center>\n";
		            echo "Your search of the Allele Table did yield any individuals.<br>\n";
		            echo "Please try a new search with different search criteria.<br>\n";
			    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		            echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                            echo "</center>\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
		          }#end if (sizeof(rec_list) == '0')
                        $indiv_table_id_term = join($indiv_table_id_array,',');

                        $field_list_array = array('individual_table_id');
			$num_of_indivs = countTableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in');
			if (!preg_match('/^\d+$/',$num_of_indivs))
                          {
                            $date = date('Y-m-d H:i:s');
                            echo "Error #134: $date<br>\n";
			    echo "Error in call to countTableQuery from individual_search.php<br>\n";
			    echo "$num_of_indivs<br><br>\n";
			    echo "Please email the above error using the Comments/Help/Support link on the \n";
			    echo "left navigation bar.\n";
			    echo "</form>\n";
			    echo "</body></html>\n";
			    $ret_val = disconnect();
			    exit;
		          }#end error in call to countTableQuery

                        #if ($num_of_indivs > $max_records_to_print)
                        #  {
                        #    echo "Your search returned $num_of_indivs individuals.<br>\n";
                        #    tooManyIndividuals($indiv_table_id_term);
                        #    $ret_val = disconnect();
                        #    exit;
                        #  }#end if more than max to print

		        if ($num_of_indivs > ($max_records_to_print_per_page * 5))
                          {
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                            $indiv_table_id_array = distinctTableQuery('individual_table_id','individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in','all',$order_by);
                            if (!is_array($indiv_table_id_array))
                              {
                                $date = date('Y-m-d H:i:s');
			        echo "Error #135: $date<br>\n";
			        echo "Error in call to distincTableQuery from individual_search.php<br>\n";
			        echo "$indiv_table_id_array<br><br>\n";
			        echo "Please email the above error using the Comments/Help/Support link on the \n";
			        echo "left navigation bar.\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if error call to distinctTableQuery
                            $all_indiv_table_id_term = join($indiv_table_id_array,',');
                            unset($indiv_table_id_array);

                            moreThanFivePages($all_indiv_table_id_term);
                            unset($all_indiv_table_id_term);
                          }#end if more than 5 pages returned

		        if ($num_of_indivs > $max_records_to_print_per_page)
		          {
			    $indiv_multiple_pages = 1;
                            $from                 = "0";
                            $to                   = $max_records_to_print_per_page - 1;
                            $range                = "$from"."-"."$to";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
			    $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in',$range,$order_by);
			    if (!is_array($indiv_rec_list))
			      {
			        $date = date('Y-m-d H:i:s');
			        echo "Error #136: $date<br>\n";
			        echo "Error in call to tableQuery from individual_search.php<br>\n";
			        echo "$indiv_rec_list<br><br>\n";
			        echo "Please email the above error using the Comments/Help/Support link on the \n";
			        echo "left navigation bar.\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if (!is_array(indiv_rec_list))
                            if (sizeof($indiv_rec_list) == '0')
			      {
			        echo "<center>\n";
			        echo "Your search of the Allele Table did not yield any individuals.<br>\n";
			        echo "Please try your search again with different search criteria.<br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
			        echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
			        echo "</center>\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if (sizeof(indiv_rec_list) == '0')
			    $final_function_call   = 'tableQuery';
			    $final_table_name      = 'individual_table';
			    $final_field_list      = $field_list_array;
			    $final_term            = $indiv_table_id_term;
			    $final_mode            = 'in';
			    $final_order_by        = $order_by;
                            $last_record_retrieved = $max_records_to_print_per_page;
                          }#end if more than a single page
                        else #only a single page
		          {
			    $indiv_multiple_pages = 0;
                            $range                = "all";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                            $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in',$range,$order_by);
		            if (!is_array($indiv_rec_list))
                              {
			        $date = date('Y-m-d H:i:s');
		                echo "Error #137: $date<br>\n";
		                echo "Error in call to tableQuery from individual_search.php<br>\n";
		                echo "indiv_rec_list<br><br>\n";
		                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar. \n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (!is_array(indiv_rec_list))
		            if (sizeof($indiv_rec_list) == '0')
                              {
                                echo "<center>\n";
		                echo "Your search of the Allele Table did not yield any individuals.<br>\n";
		                echo "Please try a new search with different search criteria.<br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (sizeof(indiv_rec_list) == '0')
			  }#end else only a single page
                      }#end if sizeof(field_list) == '1'
                    else #sizeof(field_list) > '1'
                      {
                        $marker_table_field_list = array();
                        $marker_table_search_term = "";
                        $marker_table_search_mode = "";
                        $final_query_field_list   = array();
                        $final_query_term_array   = array();
                        $final_query_mode_array   = array();
                        $num_of_fields = sizeof($field_list);
                        $num_of_modes  = sizeof($mode);
                        for ($i = '0'; $i < $num_of_fields; $i++)
                          {
                            if ($field_list[$i] == 'marker_name')
                              {
                                $place_on_field_list = ($i + 1);
                                $marker_table_field_list[] = $field_list[$i];
                                $num_of_mode_seen = '0';
                                for ($j='0'; $j<$num_of_modes; $j++)
                                  {
                                    if ($mode[$j] != 'Select Type of Search')
                                      {
                                        $num_of_mode_seen = ($num_of_mode_seen + 1);
                                        if ($place_on_field_list == $num_of_mode_seen)
                                          {
                                            $marker_table_search_term  = $term[$j];
                                            $marker_table_search_mode  = $mode[$j];
                                          }#end if right place on list
                                      }#end if real mode
                                  }#end foreach mode
                              }
                            else
                              {
                                $place_on_field_list = ($i + 1);
                                $final_query_field_list[] = $field_list[$i];
                                $num_of_mode_seen = '0';
                                for ($j='0'; $j<$num_of_modes; $j++)
                                  {
                                    if ($mode[$j] != 'Select Type of Search')
                                      {
                                        $num_of_mode_seen = ($num_of_mode_seen + 1);
                                        if ($place_on_field_list == $num_of_mode_seen)
                                          {
                                            $final_query_term_array[] = $term[$j];
                                            $final_query_mode_array[] = $mode[$j];
                                          }#end if right place on list
                                      }#end if real mode
                                  }#end foreach mode
                              }
                          }#end build search queries

                        if (sizeof($marker_table_field_list) > '0')
                          {
                            $marker_id_array = distinctTableQuery('marker_id','marker_table',$database_id,$marker_table_field_list,$marker_table_search_term,$marker_table_search_mode,'all');
                            if (!is_array($marker_id_array))
                              {
				$date = date('Y-m-d H:i:s');
                                echo "Error #138: $date<br>\n";
                                echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
                                echo "$marker_id_array<br><br>\n";
                                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
                              }#end error in call to distinctTableQuery
                            if (sizeof($marker_id_array) > '0')
                              {
                                $marker_id_term = join($marker_id_array,',');
                                $final_query_field_list[] = 'marker_id';
                                $final_query_term_array[] = $marker_id_term;
                                $final_query_mode_array[] = 'in';
				unset($marker_id_array);
                              }#end if have records
                            else #no records
                              {
                                if ($join == 'and')
                                  {
                                    echo "<center>\n";
		                    echo "Your search of the Allele Table did not yield any individuals.<br>\n";
		                    echo "Please try a new search with different search criteria.<br>\n";
				    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                    echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                    echo "</center>\n";
		                    echo "</form>\n";
		                    echo "</body></html>\n";
		                    $ret_val = disconnect();
		                    exit;
                                  }#end if join == 'and'
                              }#end else no records
                          }#end if have marker_table field

                        $rec_list = distinctCompoundTableQuery('allele_id',$table_name,$database_id,$final_query_field_list,$final_query_term_array,$final_query_mode_array,$join,'all');
                        if (!is_array($rec_list))
                          {
			    $date = date('Y-m-d H:i:s');
                            echo "Error #139: $date<br>\n";
                            echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
                            echo "$rec_list<br><br>\n";
                            echo "Please email the above error using The Comments/Help/Support link on the \n";
		            echo "left navigation bar.\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
                          }#end error in call to compoundTableQuery
                        if (sizeof($rec_list) == '0')
                          {
                            echo "<center>\n";
		            echo "Your search of the Allele Table did not yield any individuals.<br>\n";
		            echo "Please try a new search with different search criteria.<br>\n";
			    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		            echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                            echo "</center>\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
                          }#end if sizeof(rec_list) == '0'
                        $allele_id_term = join($rec_list,',');
                        unset($rec_list);
                        
                        $field_list_array = array('allele_1_id','allele_2_id');
                        $indiv_table_id_array = distinctTableQuery('individual_table_id','genotype_table',$database_id,$field_list_array,$allele_id_term,'in','all');
                        if (!is_array($indiv_table_id_array))
                          {
			    $date = date('Y-m-d H:i:s');
                            echo "Error #140: $date<br>\n";
                            echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
                            echo "$indiv_table_id_array<br><br>\n";
                            echo "Please email the above error using The Comments/Help/Support link on the \n";
		            echo "left navigation bar.\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
		          }#end error in call to distinctTableQuery
		        if (sizeof($indiv_table_id_array) == '0')
                          {
                            echo "<center>\n";
		            echo "Your search of the Allele Table did yield any individuals.<br>\n";
		            echo "Please try a new search with different search criteria.<br>\n";
			    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		            echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                            echo "</center>\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
		          }#end if (sizeof(rec_list) == '0')
                        $indiv_table_id_term = join($indiv_table_id_array,',');
			unset($indiv_table_id_array);

                        $field_list_array = array('individual_table_id');
			$num_of_indivs = countTableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in');
			if (!preg_match('/^\d+$/',$num_of_indivs))
                          {
                            $date = date('Y-m-d H:i:s');
                            echo "Error #141: $date<br>\n";
			    echo "Error in call to countTableQuery from individual_search.php<br>\n";
			    echo "$num_of_indivs<br><br>\n";
			    echo "Please email the above error using the Comments/Help/Support link on the \n";
			    echo "left navigation bar.\n";
			    echo "</form>\n";
			    echo "</body></html>\n";
			    $ret_val = disconnect();
			    exit;
		          }#end error in call to countTableQuery

                        #if ($num_of_indivs > $max_records_to_print)
                        #  {
                        #    echo "Your search returned $num_of_indivs individuals.<br>\n";
                        #    tooManyIndividuals($indiv_table_id_term);
                        #    $ret_val = disconnect();
                        #    exit;
                        #  }#end if more than max to print

		        if ($num_of_indivs > ($max_records_to_print_per_page * 5))
                          {
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                            $indiv_table_id_array = distinctTableQuery('individual_table_id','individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in','all',$order_by);
                            if (!is_array($indiv_table_id_array))
                              {
                                $date = date('Y-m-d H:i:s');
			        echo "Error #142: $date<br>\n";
			        echo "Error in call to distincTableQuery from individual_search.php<br>\n";
			        echo "$indiv_table_id_array<br><br>\n";
			        echo "Please email the above error using the Comments/Help/Support link on the \n";
			        echo "left navigation bar.\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if error call to distinctTableQuery
                            $all_indiv_table_id_term = join($indiv_table_id_array,',');
                            unset($indiv_table_id_array);

                            moreThanFivePages($all_indiv_table_id_term);
                            unset($all_indiv_table_id_term);
                          }#end if more than 5 pages returned

		        if ($num_of_indivs > $max_records_to_print_per_page)
		          {
			    $indiv_multiple_pages = 1;
                            $from                 = "0";
                            $to                   = $max_records_to_print_per_page - 1;
                            $range                = "$from"."-"."$to";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
			    $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in',$range,$order_by);
			    if (!is_array($indiv_rec_list))
			      {
			        $date = date('Y-m-d H:i:s');
			        echo "Error #143: $date<br>\n";
			        echo "Error in call to tableQuery from individual_search.php<br>\n";
			        echo "$indiv_rec_list<br><br>\n";
			        echo "Please email the above error using the Comments/Help/Support link on the \n";
			        echo "left navigation bar.\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if (!is_array(indiv_rec_list))
                            if (sizeof($indiv_rec_list) == '0')
			      {
			        echo "<center>\n";
			        echo "Your search of the Allele Table did not yield any individuals.<br>\n";
			        echo "Please try your search again with different search criteria.<br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
			        echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
			        echo "</center>\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if (sizeof(indiv_rec_list) == '0')
			    $final_function_call   = 'tableQuery';
			    $final_table_name      = 'individual_table';
			    $final_field_list      = $field_list_array;
			    $final_term            = $indiv_table_id_term;
			    $final_mode            = 'in';
			    $final_order_by        = $order_by;
                            $last_record_retrieved = $max_records_to_print_per_page;
                          }#end if more than a single page
                        else #only a single page
		          {
			    $indiv_multiple_pages = 0;
                            $range                = "all";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                            $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in',$range,$order_by);
		            if (!is_array($indiv_rec_list))
                              {
			        $date = date('Y-m-d H:i:s');
		                echo "Error #144: $date<br>\n";
		                echo "Error in call to tableQuery from individual_search.php<br>\n";
		                echo "indiv_rec_list<br><br>\n";
		                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar. \n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (!is_array(indiv_rec_list))
		            if (sizeof($indiv_rec_list) == '0')
                              {
                                echo "<center>\n";
		                echo "Your search of the Allele Table did not yield any individuals.<br>\n";
		                echo "Please try a new search with different search criteria.<br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (sizeof(indiv_rec_list) == '0')
			  }#end else only a single page
                      }#end else sizeof(field_list) > '1'
		   }#end if (table_name == 'allele_table')

		 elseif ($table_name == 'phenotype_table')
                   {
                     if (sizeof($field_list) == '1')
                       {
                         $num_of_modes = sizeof($mode);
                         for ($i = '0'; $i < $num_of_modes; $i++)
                           {
                             if ($mode[$i] != 'Select Type of Search')
                               {
                                 $search_term = $term[$i];
                                 $search_mode = $mode[$i];
                               }
                           }#end determine which term and mode to use

		         $rec_list_1 = distinctTableJoin('individual_table_id',$table_name,'qualitative_phenotype_value_table',$database_id,$field_list,$search_term,$search_mode,'all');
		         if (!is_array($rec_list_1))
                           {
			     $date = date('Y-m-d H:i:s');
		             echo "Error #145: $date<br>\n";
		             echo "Error in call to distinctTableJoin from individual_search.php<br>\n";
		             echo "$rec_list_1<br><br>\n";
		             echo "Please email the above error using The Comments/Help/Support link on the \n";
		             echo "left navigation bar.\n";
		             echo "</form>\n";
		             echo "</body></html>\n";
		             $ret_val = disconnect();
		             exit;
		           }#end error in call to distinctTableJoin

                         $rec_list_2 = distinctTableJoin('individual_table_id',$table_name,'quantitative_phenotype_value_table',$database_id,$field_list,$search_term,$search_mode,'all');
		         if (!is_array($rec_list_2))
                           {
			     $date = date('Y-m-d H:i:s');
		             echo "Error #146: $date<br>\n";
		             echo "Error in call to distinctTableJoin from individual_search.php<br>\n";
		             echo "$rec_list_2<br><br>\n";
		             echo "Please email the above error using The Comments/Help/Support link on the \n";
		             echo "left navigation bar.\n";
		             echo "</form>\n";
		             echo "</body></html>\n";
		             $ret_val = disconnect();
		             exit;
		           }#end error in call to distinctTableJoin
		         if ((sizeof($rec_list_1) == '0') and (sizeof($rec_list_2) == '0'))
                           {
                             echo "<center>\n";
		             echo "Your search of the Phenotype Table did yield any individuals.<br>\n";
		             echo "Please try a new search with different search criteria.<br>\n";
			     echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		             echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                             echo "</center>\n";
		             echo "</form>\n";
		             echo "</body></html>\n";
		             $ret_val = disconnect();
		             exit;
		           }#end if (sizeof(rec_list) == '0')
                         if ((sizeof($rec_list_1) > '0') and (sizeof($rec_list_2) == '0'))
		           { $indiv_table_id_term = join($rec_list_1,',');}
                         elseif ((sizeof($rec_list_2) > '0') and (sizeof($rec_list_1) == '0'))
                           { $indiv_table_id_term = join($rec_list_2,',');}
                         else
                           {
                             $indiv_table_id_term = join($rec_list_1,',');
                             $indiv_table_id_term.= ",";
                             $indiv_table_id_term.= join($rec_list_2,',');
                           }
			 unset($rec_list_1);
                         unset($rec_list_2);

		         $field_list_array = array('individual_table_id');
			 $num_of_indivs = countTableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in');
			 if (!preg_match('/^\d+$/',$num_of_indivs))
                          {
                            $date = date('Y-m-d H:i:s');
                            echo "Error #147: $date<br>\n";
			    echo "Error in call to countTableQuery from individual_search.php<br>\n";
			    echo "$num_of_indivs<br><br>\n";
			    echo "Please email the above error using the Comments/Help/Support link on the \n";
			    echo "left navigation bar.\n";
			    echo "</form>\n";
			    echo "</body></html>\n";
			    $ret_val = disconnect();
			    exit;
		          }#end error in call to countTableQuery

                        #if ($num_of_indivs > $max_records_to_print)
                        #  {
                        #    echo "Your search returned $num_of_indivs individuals.<br>\n";
                        #    tooManyIndividuals($indiv_table_id_term);
                        #    $ret_val = disconnect();
                        #    exit;
                        #  }#end if more than max to print

		        if ($num_of_indivs > ($max_records_to_print_per_page * 5))
                          {
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                            $indiv_table_id_array = distinctTableQuery('individual_table_id','individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in','all',$order_by);
                            if (!is_array($indiv_table_id_array))
                              {
                                $date = date('Y-m-d H:i:s');
			        echo "Error #148: $date<br>\n";
			        echo "Error in call to distincTableQuery from individual_search.php<br>\n";
			        echo "$indiv_table_id_array<br><br>\n";
			        echo "Please email the above error using the Comments/Help/Support link on the \n";
			        echo "left navigation bar.\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if error call to distinctTableQuery
                            $all_indiv_table_id_term = join($indiv_table_id_array,',');
                            unset($indiv_table_id_array);

                            moreThanFivePages($all_indiv_table_id_term);
                            unset($all_indiv_table_id_term);
                          }#end if more than 5 pages returned

		        if ($num_of_indivs > $max_records_to_print_per_page)
		          {
			    $indiv_multiple_pages = 1;
                            $from                 = "0";
                            $to                   = $max_records_to_print_per_page - 1;
                            $range                = "$from"."-"."$to";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
			    $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in',$range,$order_by);
			    if (!is_array($indiv_rec_list))
			      {
			        $date = date('Y-m-d H:i:s');
			        echo "Error #149: $date<br>\n";
			        echo "Error in call to tableQuery from individual_search.php<br>\n";
			        echo "$indiv_rec_list<br><br>\n";
			        echo "Please email the above error using the Comments/Help/Support link on the \n";
			        echo "left navigation bar.\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if (!is_array(indiv_rec_list))
                            if (sizeof($indiv_rec_list) == '0')
			      {
			        echo "<center>\n";
			        echo "Your search of the Phenotype Table did not yield any individuals.<br>\n";
			        echo "Please try your search again with different search criteria.<br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
			        echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
			        echo "</center>\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if (sizeof(indiv_rec_list) == '0')
			    $final_function_call   = 'tableQuery';
			    $final_table_name      = 'individual_table';
			    $final_field_list      = $field_list_array;
			    $final_term            = $indiv_table_id_term;
			    $final_mode            = 'in';
			    $final_order_by        = $order_by;
                            $last_record_retrieved = $max_records_to_print_per_page;
                          }#end if more than a single page
                        else #only a single page
		          {
			    $indiv_multiple_pages = 0;
                            $range                = "all";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
		            $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in',$range,$order_by);
		            if (!is_array($indiv_rec_list))
                              {
			        $date = date('Y-m-d H:i:s');
		                echo "Error #150: $date<br>\n";
		                echo "Error in call to tableQuery from individual_search.php<br>\n";
		                echo "indiv_rec_list<br><br>\n";
		                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar. \n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (!is_array(indiv_rec_list))
		            if (sizeof($indiv_rec_list) == '0')
                              {
                                echo "<center>\n";
		                echo "Your search of the Phenotype Table did not yield any individuals.<br>\n";
		                echo "Please try a new search with different search criteria.<br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (sizeof(indiv_rec_list) == '0')
			  }#end else only a single page
                       }#end if sizeof(field_list) == '1'
                     else #sizeof(field_list) > '1'
                       {
                         $term_array = array();
                         $mode_array = array();
                         $num_of_fields = sizeof($field_list);
                         $num_of_modes  = sizeof($mode);
                         for ($i='0'; $i<$num_of_fields; $i++)
                           {
                             $place_on_field_list = ($i + 1);
                             $num_of_mode_seen = '0';
                             for ($j='0'; $j<$num_of_modes; $j++)
                               {
                                 if ($mode[$j] != 'Select Type of Search')
                                   {
                                     $num_of_mode_seen = ($num_of_mode_seen + 1);
                                     if ($place_on_field_list == $num_of_mode_seen)
                                       {
                                         $term_array[] = $term[$j];
                                         $mode_array[] = $mode[$j];
                                       }#end right place on list
                                   }#end if real mode
                               }#end foreach mode
                           }#end build search queries

                         $phenotype_id_array = distinctCompoundTableQuery('phenotype_id',$table_name,$database_id,$field_list,$term_array,$mode_array,$join,'all');
                         if (!is_array($phenotype_id_array))
                           {
			     $date = date('Y-m-d H:i:s');
                             echo "Error #151: $date<br>\n";
                             echo "Error in call to compoundTableQuery from individual_search.php<br>\n";
                             echo "$phenotype_id_array<br><br>\n";
                             echo "Please email the above error using The Comments/Help/Support link on the \n";
		             echo "left navigation bar.\n";
		             echo "</form>\n";
		             echo "</body></html>\n";
		             $ret_val = disconnect();
		             exit;
                           }#end error in call to compoundTableQuery
                         if (sizeof($phenotype_id_array) == '0')
                           {
                             echo "<center>\n";
		             echo "Your search of the Phenotype Table did not yield any individuals.<br>\n";
		             echo "Please try a new search with different search criteria.<br>\n";
			     echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		             echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                             echo "</center>\n";
		             echo "</form>\n";
		             echo "</body></html>\n";
		             $ret_val = disconnect();
		             exit;
                           }#end if sizeof(rec_list) == '0'
                         $phenotype_id_term = join($phenotype_id_array,',');
			 unset($phenotype_id_array);
                         
                         $field_list_array = array('phenotype_id');
                         $rec_list_1 = distinctTableQuery('individual_table_id','qualitative_phenotype_value_table',$database_id,$field_list_array,$phenotype_id_term,'in','all');
		         if (!is_array($rec_list_1))
                           {
			     $date = date('Y-m-d H:i:s');
		             echo "Error #152: $date<br>\n";
		             echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
		             echo "$rec_list_1<br><br>\n";
		             echo "Please email the above error using The Comments/Help/Support link on the \n";
		             echo "left navigation bar.\n";
		             echo "</form>\n";
		             echo "</body></html>\n";
		             $ret_val = disconnect();
		             exit;
		           }#end error in call to distinctTableQuery

                         $rec_list_2 = distinctTableQuery('individual_table_id','quantitative_phenotype_value_table',$database_id,$field_list_array,$phenotype_id_term,'in','all');
		         if (!is_array($rec_list_2))
                           {
			     $date = date('Y-m-d H:i:s');
		             echo "Error #153: $date<br>\n";
		             echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
		             echo "$rec_list_2<br><br>\n";
		             echo "Please email the above error using The Comments/Help/Support link on the \n";
		             echo "left navigation bar.\n";
		             echo "</form>\n";
		             echo "</body></html>\n";
		             $ret_val = disconnect();
		             exit;
		           }#end error in call to distinctTableQuery
		         if ((sizeof($rec_list_1) == '0') and (sizeof($rec_list_2) == '0'))
                           {
                             echo "<center>\n";
		             echo "Your search of the Phenotype Table did yield any individuals.<br>\n";
		             echo "Please try a new search with different search criteria.<br>\n";
			     echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		             echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                             echo "</center>\n";
		             echo "</form>\n";
		             echo "</body></html>\n";
		             $ret_val = disconnect();
		             exit;
		           }#end if (sizeof(rec_list) == '0')
                         if ((sizeof($rec_list_1) > '0') and (sizeof($rec_list_2) == '0'))
		           { $indiv_table_id_term = join($rec_list_1,',');}
                         elseif ((sizeof($rec_list_2) > '0') and (sizeof($rec_list_1) == '0'))
                           { $indiv_table_id_term = join($rec_list_2,',');}
                         else
                           {
                             $indiv_table_id_term = join($rec_list_1,',');
                             $indiv_table_id_term.= ",";
                             $indiv_table_id_term.= join($rec_list_2,',');
                           }
			 unset($rec_list_1);
                         unset($rec_list_2);

		         $field_list_array = array('individual_table_id');
			 $num_of_indivs = countTableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in');
			 if (!preg_match('/^\d+$/',$num_of_indivs))
                          {
                            $date = date('Y-m-d H:i:s');
                            echo "Error #154: $date<br>\n";
			    echo "Error in call to countTableQuery from individual_search.php<br>\n";
			    echo "$num_of_indivs<br><br>\n";
			    echo "Please email the above error using the Comments/Help/Support link on the \n";
			    echo "left navigation bar.\n";
			    echo "</form>\n";
			    echo "</body></html>\n";
			    $ret_val = disconnect();
			    exit;
		          }#end error in call to countTableQuery

                        #if ($num_of_indivs > $max_records_to_print)
                        #  {
                        #    echo "Your search returned $num_of_indivs individuals.<br>\n";
                        #    tooManyIndividuals($indiv_table_id_term);
                        #    $ret_val = disconnect();
                        #    exit;
                        #  }#end if more than max to print

		        if ($num_of_indivs > ($max_records_to_print_per_page * 5))
                          {
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                            $indiv_table_id_array = distinctTableQuery('individual_table_id','individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in','all',$order_by);
                            if (!is_array($indiv_table_id_array))
                              {
                                $date = date('Y-m-d H:i:s');
			        echo "Error #155: $date<br>\n";
			        echo "Error in call to distincTableQuery from individual_search.php<br>\n";
			        echo "$indiv_table_id_array<br><br>\n";
			        echo "Please email the above error using the Comments/Help/Support link on the \n";
			        echo "left navigation bar.\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if error call to distinctTableQuery
                            $all_indiv_table_id_term = join($indiv_table_id_array,',');
                            unset($indiv_table_id_array);

                            moreThanFivePages($all_indiv_table_id_term);
                            unset($all_indiv_table_id_term);
                          }#end if more than 5 pages returned

		        if ($num_of_indivs > $max_records_to_print_per_page)
		          {
			    $indiv_multiple_pages = 1;
                            $from                 = "0";
                            $to                   = $max_records_to_print_per_page - 1;
                            $range                = "$from"."-"."$to";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
			    $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in',$range,$order_by);
			    if (!is_array($indiv_rec_list))
			      {
			        $date = date('Y-m-d H:i:s');
			        echo "Error #156: $date<br>\n";
			        echo "Error in call to tableQuery from individual_search.php<br>\n";
			        echo "$indiv_rec_list<br><br>\n";
			        echo "Please email the above error using the Comments/Help/Support link on the \n";
			        echo "left navigation bar.\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if (!is_array(indiv_rec_list))
                            if (sizeof($indiv_rec_list) == '0')
			      {
			        echo "<center>\n";
			        echo "Your search of the Phenotype Table did not yield any individuals.<br>\n";
			        echo "Please try your search again with different search criteria.<br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
			        echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
			        echo "</center>\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if (sizeof(indiv_rec_list) == '0')
			    $final_function_call   = 'tableQuery';
			    $final_table_name      = 'individual_table';
			    $final_field_list      = $field_list_array;
			    $final_term            = $indiv_table_id_term;
			    $final_mode            = 'in';
			    $final_order_by        = $order_by;
                            $last_record_retrieved = $max_records_to_print_per_page;
                          }#end if more than a single page
                        else #only a single page
		          {
			    $indiv_multiple_pages = 0;
                            $range                = "all";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
		            $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in',$range,$order_by);
		            if (!is_array($indiv_rec_list))
                              {
			        $date = date('Y-m-d H:i:s');
		                echo "Error #157: $date<br>\n";
		                echo "Error in call to tableQuery from individual_search.php<br>\n";
		                echo "indiv_rec_list<br><br>\n";
		                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar. \n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (!is_array(indiv_rec_list))
		            if (sizeof($indiv_rec_list) == '0')
                              {
                                echo "<center>\n";
		                echo "Your search of the Phenotype Table did not yield any individuals.<br>\n";
		                echo "Please try a new search with different search criteria.<br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (sizeof(indiv_rec_list) == '0')
			  }#end else only a single page
                       }#end else sizeof(field_list) > '1'
		   }#end if (table_name == 'phenotype_table')

		 elseif ($table_name == 'phenotype_value_table')
                   {
                    if (sizeof($field_list) == '1')
                      {
                        $num_of_modes = sizeof($mode);
                        for ($i = '0'; $i < $num_of_modes; $i++)
                          {
                            if ($mode[$i] != 'Select Type of Search')
                              {
                                $search_term = $term[$i];
                                $search_mode = $mode[$i];
                              }
                          }#end determine which term and mode to use

                        if (($field_list[0] == 'individual_id') or ($field_list[0] == 'pedigree_id'))
                          {
                            $indiv_table_id_array = distinctTableJoin('individual_table_id','individual_table',$table_name,$database_id,$field_list,$search_term,$search_mode,'all');
                            if (!is_array($indiv_table_id_array))
                              {
				$date = date('Y-m-d H:i:s');
                                echo "Error #158: $date<br>\n";
                                echo "Error in call to distinctTableJoin from individual_search.php<br>\n";
                                echo "$indiv_table_id_array<br><br>\n";
                                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
                              }#end error in call to distinctTableJoin
                            if (sizeof($indiv_table_id_array) == '0')
                              {
                                echo "<center>\n";
		                echo "Your search of the Phenotype Value Table did not yield any individuals.<br>\n";
		                echo "Please try a new search with different search criteria.<br>\n";
				echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
                              }#end if sizeof(rec_list) == '0'
                            $indiv_table_id_term = join($indiv_table_id_array,',');
			    unset($indiv_table_id_array);
                          }#end if individual_table fields
                        elseif ($field_list[0] == 'phenotype_name')
                          {
                            $rec_list_1 = distinctTableJoin('individual_table_id','qualitative_phenotype_table',$table_name,$database_id,$field_list,$search_term,$search_mode,'all');
                            if (!is_array($rec_list_1))
                              {
				$date = date('Y-m-d H:i:s');
                                echo "Error #159: $date<br>\n";
                                echo "Error in call to distinctTableJoin from individual_search.php<br>\n";
                                echo "$rec_list_1<br><br>\n";
                                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
                              }#end error in call to distinctTableJoin

                            $rec_list_2 = distinctTableJoin('individual_table_id','quantitative_phenotype_table',$table_name,$database_id,$field_list,$search_term,$search_mode,'all');
                            if (!is_array($rec_list_2))
                              {
				$date = date('Y-m-d H:i:s');
                                echo "Error #160: $date<br>\n";
                                echo "Error in call to distinctTableJoin from individual_search.php<br>\n";
                                echo "$rec_list_2<br><br>\n";
                                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
                              }#end error in call to distinctTableJoin
                            if ((sizeof($rec_list_1) == '0') and (sizeof($rec_list_2) == '0'))
                              {
                                echo "<center>\n";
		                echo "Your search of the Phenotype Value Table did not yield any individuals.<br>\n";
		                echo "Please try a new search with different search criteria.<br>\n";
				echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
                              }#end if sizeof(rec_list) == '0'
                            if ((sizeof($rec_list_1) > '0') and (sizeof($rec_list_2) == '0'))
                              { $indiv_table_id_term = join($rec_list_1,',');}
                            if ((sizeof($rec_list_2) > '0') and (sizeof($rec_list_1) == '0'))
                              { $indiv_table_id_term = join($rec_list_2,',');}
                            else
                              {
                                $indiv_table_id_term = join($rec_list_1,',');
                                $indiv_table_id_term.= ",";
                                $indiv_table_id_term.= join($rec_list_2,',');
                              }
			    unset($rec_list_1);
                            unset($rec_list_2);
                          }#end if phenotype_table field
                        else #phenotype_value_table field
                          {
		            $rec_list_1 = distinctTableQuery('individual_table_id','qualitative_phenotype_value_table',$database_id,$field_list,$search_term,$search_mode,'all');
		            if (!is_array($rec_list_1))
                              {
				$date = date('Y-m-d H:i:s');
		                echo "Error #161: $date<br>\n";
		                echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
		                echo "$rec_list_1<br><br>\n";
		                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end error in call to distinctTableQuery

                            $rec_list_2 = distinctTableQuery('individual_table_id','quantitative_phenotype_value_table',$database_id,$field_list,$search_term,$search_mode,'all');
		            if (!is_array($rec_list_2))
                              {
				$date = date('Y-m-d H:i:s');
		                echo "Error #162: $date<br>\n";
		                echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
		                echo "$rec_list_2<br><br>\n";
		                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end error in call to distinctTableQuery
		            if ((sizeof($rec_list_1) == '0') and (sizeof($rec_list_2) == '0'))
                              {
                                echo "<center>\n";
		                echo "Your search of the Phenotype Value Table did not yield any individuals.<br>\n";
		                echo "Please try a new search with different search criteria.<br>\n";
				echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (sizeof(rec_list) == '0')
                            if ((sizeof($rec_list_1) > '0') and (sizeof($rec_list_2) == '0'))
                              { $indiv_table_id_term = join($rec_list_1,',');}
                            if ((sizeof($rec_list_2) > '0') and (sizeof($rec_list_1) == '0'))
                              { $indiv_table_id_term = join($rec_list_2,',');}
                            else
                              {
                                $indiv_table_id_term = join($rec_list_1,',');
                                $indiv_table_id_term.= ",";
                                $indiv_table_id_term.= join($rec_list_2,',');
                              }
			    unset($rec_list_1);
                            unset($rec_list_2);
                          }#end else phenotype_value_table field

		        $field_list_array = array('individual_table_id');
			$num_of_indivs = countTableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in');
			if (!preg_match('/^\d+$/',$num_of_indivs))
                          {
                            $date = date('Y-m-d H:i:s');
                            echo "Error #163: $date<br>\n";
			    echo "Error in call to countTableQuery from individual_search.php<br>\n";
			    echo "$num_of_indivs<br><br>\n";
			    echo "Please email the above error using the Comments/Help/Support link on the \n";
			    echo "left navigation bar.\n";
			    echo "</form>\n";
			    echo "</body></html>\n";
			    $ret_val = disconnect();
			    exit;
		          }#end error in call to countTableQuery

                        #if ($num_of_indivs > $max_records_to_print)
                        #  {
                        #    echo "Your search returned $num_of_indivs individuals.<br>\n";
                        #    tooManyIndividuals($indiv_table_id_term);
                        #    $ret_val = disconnect();
                        #    exit;
                        #  }#end if more than max to print

		        if ($num_of_indivs > ($max_records_to_print_per_page * 5))
                          {
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                            $indiv_table_id_array = distinctTableQuery('individual_table_id','individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in','all',$order_by);
                            if (!is_array($indiv_table_id_array))
                              {
                                $date = date('Y-m-d H:i:s');
			        echo "Error #164: $date<br>\n";
			        echo "Error in call to distincTableQuery from individual_search.php<br>\n";
			        echo "$indiv_table_id_array<br><br>\n";
			        echo "Please email the above error using the Comments/Help/Support link on the \n";
			        echo "left navigation bar.\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if error call to distinctTableQuery
                            $all_indiv_table_id_term = join($indiv_table_id_array,',');
                            unset($indiv_table_id_array);

                            moreThanFivePages($all_indiv_table_id_term);
                            unset($all_indiv_table_id_term);
                          }#end if more than 5 pages returned

		        if ($num_of_indivs > $max_records_to_print_per_page)
		          {
			    $indiv_multiple_pages = 1;
                            $from                 = "0";
                            $to                   = $max_records_to_print_per_page - 1;
                            $range                = "$from"."-"."$to";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
			    $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in',$range,$order_by);
			    if (!is_array($indiv_rec_list))
			      {
			        $date = date('Y-m-d H:i:s');
			        echo "Error #165: $date<br>\n";
			        echo "Error in call to tableQuery from individual_search.php<br>\n";
			        echo "$indiv_rec_list<br><br>\n";
			        echo "Please email the above error using the Comments/Help/Support link on the \n";
			        echo "left navigation bar.\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if (!is_array(indiv_rec_list))
                            if (sizeof($indiv_rec_list) == '0')
			      {
			        echo "<center>\n";
			        echo "Your search of the Phenotype Value Table did not yield any individuals.<br>\n";
			        echo "Please try your search again with different search criteria.<br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
			        echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
			        echo "</center>\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if (sizeof(indiv_rec_list) == '0')
			    $final_function_call   = 'tableQuery';
			    $final_table_name      = 'individual_table';
			    $final_field_list      = $field_list_array;
			    $final_term            = $indiv_table_id_term;
			    $final_mode            = 'in';
			    $final_order_by        = $order_by;
                            $last_record_retrieved = $max_records_to_print_per_page;
                          }#end if more than a single page
                        else #only a single page
		          {
			    $indiv_multiple_pages = 0;
                            $range                = "all";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
		            $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in',$range,$order_by);
		            if (!is_array($indiv_rec_list))
                              {
			        $date = date('Y-m-d H:i:s');
		                echo "Error #166: $date<br>\n";
		                echo "Error in call to tableQuery from individual_search.php<br>\n";
		                echo "$indiv_rec_list<br><br>\n";
		                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (!is_array(indiv_rec_list))
		            if (sizeof($indiv_rec_list) == '0')
                              {
                                echo "<center>\n";
		                echo "Your search of the Phenotype Value Table did not yield any individuals.<br>\n";
		                echo "Please try a new search with different search criteria.<br><br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (sizeof(indiv_rec_list) == '0')
			  }#end else only a single page
                      }#end if sizeof(field_list) == '1'
                    else #sizeof(field_list) > '1'
                      {
                        $individual_table_field_list = array();
                        $individual_table_term_array = array();
                        $individual_table_mode_array = array();
                        $phenotype_table_field_list  = array();
                        $phenotype_table_term_array  = array();
                        $phenotype_table_mode_array  = array();
                        $final_query_field_list      = array();
                        $final_query_term_array      = array();
                        $final_query_mode_array      = array();
                        $num_of_fields               = sizeof($field_list);
                        $num_of_modes                = sizeof($mode);
                        for ($i = 0; $i < $num_of_fields; $i++)
                          {
                            if (($field_list[$i] == 'individual_id') or ($field_list[$i] == 'pedigree_id'))
                              {
                                $place_on_field_list = ($i + 1);
                                $individual_table_field_list[] = $field_list[$i];
                                $num_of_mode_seen = '0';
                                for ($j='0'; $j<$num_of_modes; $j++)
                                  {
                                    if ($mode[$j] != 'Select Type of Search')
                                      {
                                        $num_of_mode_seen = ($num_of_mode_seen + 1);
                                        if ($place_on_field_list == $num_of_mode_seen)
                                          {
                                            $individual_table_term_array[] = $term[$j];
                                            $individual_table_mode_array[] = $mode[$j];
                                          }#end if right place on list
                                      }#end if real mode
                                  }#end foreach mode
                              }
                            elseif (($field_list[$i] == 'phenotype_name') or ($field_list[$i] == 'type_of_phenotype'))
                              {
                                $place_on_field_list = ($i + 1);
                                $phenotype_table_field_list[] = $field_list[$i];
                                $num_of_mode_seen = '0';
                                for ($j='0'; $j<$num_of_modes; $j++)
                                  {
                                    if ($mode[$j] != 'Select Type of Search')
                                      {
                                        $num_of_mode_seen = ($num_of_mode_seen + 1);
                                        if ($place_on_field_list == $num_of_mode_seen)
                                          {
                                            $phenotype_table_term_array[]  = $term[$j];
                                            $phenotype_table_mode_array[]  = $mode[$j];
                                          }#end if right place on list
                                      }#end if real mode
                                  }#end foreach mode
                              }
                            else
                              {
                                $place_on_field_list = ($i + 1);
                                $final_query_field_list[] = $field_list[$i];
                                $num_of_mode_seen = '0';
                                for ($j='0'; $j<$num_of_modes; $j++)
                                  {
                                    if ($mode[$j] != 'Select Type of Search')
                                      {
                                        $num_of_mode_seen = ($num_of_mode_seen + 1);
                                        if ($place_on_field_list == $num_of_mode_seen)
                                          {
                                            $final_query_term_array[] = $term[$j];
                                            $final_query_mode_array[] = $mode[$j];
                                          }#end if right place on list
                                      }#end if real mode
                                  }#end foreach mode
                              }
                          }#end build search queries

                        if (sizeof($individual_table_field_list) > '0')
                          {
                            if (sizeof($individual_table_field_list) > '1')
                              {
                                $indiv_table_id_array = distinctCompoundTableQuery('individual_table_id','individual_table',$database_id,$individual_table_field_list,$individual_table_term_array,$individual_table_mode_array,$join,'all');
                                if (!is_array($indiv_table_id_array))
                                  {
				    $date = date('Y-m-d H:i:s');
                                    echo "Error #167: $date<br>\n";
                                    echo "Error in call to compoundTableQuery from individual_search.php<br>\n";
                                    echo "$indiv_table_id_array<br><br>\n";
                                    echo "Please email the above error using The Comments/Help/Support link on the \n";
		                    echo "left navigation bar.\n";
		                    echo "</form>\n";
		                    echo "</body></html>\n";
		                    $ret_val = disconnect();
		                    exit;
                                  }#end error in call to compoundTableQuery
                                if (sizeof($indiv_table_id_array) > '0')
                                  {
                                    $indiv_table_id_term = join($indiv_table_id_array,',');
                                    $final_query_field_list[] = 'individual_table_id';
                                    $final_query_term_array[] = $indiv_table_id_term;
                                    $final_query_mode_array[] = 'in';
				    unset($indiv_table_id_array);
                                  }#end if have records
                                else #no records
                                  {
                                    if ($join == 'and')
                                      {
                                        echo "<center>\n";
		                        echo "Your search of the Phenotype Value Table did not yield any individuals.<br>\n";
		                        echo "Please try a new search with different search criteria.<br>\n";
					echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                        echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                        echo "</center>\n";
		                        echo "</form>\n";
		                        echo "</body></html>\n";
		                        $ret_val = disconnect();
		                        exit;
                                      }#end if join == and
                                  }#end else no records
                              }#end more than one field
                            else
                              {
                                $indiv_table_id_array = distinctTableQuery('individual_table_id','individual_table',$database_id,$individual_table_field_list,$individual_table_term_array[0],$individual_table_mode_array[0],'all');
                                if (!is_array($indiv_table_id_array))
                                  {
				    $date = date('Y-m-d H:i:s');
                                    echo "Error #168: $date<br>\n";
                                    echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
                                    echo "$indiv_table_id_array<br><br>\n";
                                    echo "Please email the above error using The Comments/Help/Support link on the \n";
		                    echo "left navigation bar.\n";
		                    echo "</form>\n";
		                    echo "</body></html>\n";
		                    $ret_val = disconnect();
		                    exit;
                                  }#end error in call to distinctTableQuery
                                if (sizeof($indiv_table_id_array) > '0')
                                  {
                                    $indiv_table_id_term = join($indiv_table_id_array,',');
                                    $final_query_field_list[] = 'individual_table_id';
                                    $final_query_term_array[] = $indiv_table_id_term;
                                    $final_query_mode_array[] = 'in';
				    unset($indiv_table_id_array);
                                  }#end if have records
                                else #no records
                                  {
                                    if ($join == 'and')
                                      {
                                        echo "<center>\n";
		                        echo "Your search of the Phenotype Value Table did not yield any individuals.<br>\n";
		                        echo "Please try a new search with different search criteria.<br>\n";
					echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                        echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                        echo "</center>\n";
		                        echo "</form>\n";
		                        echo "</body></html>\n";
		                        $ret_val = disconnect();
		                        exit;
                                      }#end if join == and
                                  }#end else no records
                              }#end else only have one field
                          }#end if have individual table fields

                        if (sizeof($phenotype_table_field_list) > '0')
                          {
                            $phenotype_id_array = distinctCompoundTableQuery('phenotype_id','phenotype_table',$database_id,$phenotype_table_field_list,$phenotype_table_term_array,$phenotype_table_mode_array,$join,'all');
                            if (!is_array($phenotype_id_array))
                              {
				$date = date('Y-m-d H:i:s');
                                echo "Error #169: $date<br>\n";
                                echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
                                echo "$phenotype_id_array<br><br>\n";
                                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
                              }#end error in call to distinctCompoundTableQuery
                            if (sizeof($phenotype_id_array) > '0')
                              {
                                $phenotype_id_term = join($phenotype_id_array,',');
                                $final_query_field_list[] = 'phenotype_id';
                                $final_query_term_array[] = $phenotype_id_term;
                                $final_query_mode_array[] = 'in';
				unset($phenotype_id_array);
                              }#end if have records
                            else #no records
                              {
                                if ($join == 'and')
                                  {
                                    echo "<center>\n";
		                    echo "Your search of the Phenotype Value Table did not yield any individuals.<br>\n";
		                    echo "Please try a new search with different search criteria.<br>\n";
				    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                    echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                    echo "</center>\n";
		                    echo "</form>\n";
		                    echo "</body></html>\n";
		                    $ret_val = disconnect();
		                    exit;
                                  }#end if join == and
                              }#end else no records
                          }#end if have phenotype table field
                        
                        $rec_list_1 = distinctCompoundTableQuery('individual_table_id','qualitative_phenotype_value_table',$database_id,$final_query_field_list,$final_query_term_array,$final_query_mode_array,$join,'all');
                        if (!is_array($rec_list_1))
                          {
			    $date = date('Y-m-d H:i:s');
                            echo "Error #170: $date<br>\n";
                            echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
                            echo "$rec_list_1<br><br>\n";
                            echo "Please email the above error using The Comments/Help/Support link on the \n";
		            echo "left navigation bar.\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
                          }#end error  in call to distinctCompoundTableQuery

                        $rec_list_2 = distinctCompoundTableQuery('individual_table_id','quantitative_phenotype_value_table',$database_id,$final_query_field_list,$final_query_term_array,$final_query_mode_array,$join,'all');
                        if (!is_array($rec_list_2))
                          {
			    $date = date('Y-m-d H:i:s');
                            echo "Error #171: $date<br>\n";
                            echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
                            echo "$rec_list_2<br><br>\n";
                            echo "Please email the above error using The Comments/Help/Support link on the \n";
		            echo "left navigation bar.\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
                          }#end error  in call to distinctCompoundTableQuery
                        if ((sizeof($rec_list_1) == '0') and (sizeof($rec_list_2) == '0'))
                          {
                            echo "<center>\n";
		            echo "Your search of the Phenotype Value Table did not yield any individuals.<br>\n";
		            echo "Please try a new search with different search criteria.<br><br>\n";
			    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		            echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                            echo "</center>\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
                          }#end if no records
                        if ((sizeof($rec_list_1) > '0') and (sizeof($rec_list_2) == '0'))
                          { $indiv_table_id_term = join($rec_list_1,',');}
                        if ((sizeof($rec_list_2) > '0') and (sizeof($rec_list_1) == '0'))
                          { $indiv_table_id_term = join($rec_list_2,',');}
                        else
                          {
                            $indiv_table_id_term = join($rec_list_1,',');
                            $indiv_table_id_term.= ",";
                            $indiv_table_id_term.= join($rec_list_2,',');
                          }
			unset($rec_list_1);
                        unset($rec_list_2);

                        $field_list_array = array('individual_table_id');
			$num_of_indivs = countTableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in');
			if (!preg_match('/^\d+$/',$num_of_indivs))
                          {
                            $date = date('Y-m-d H:i:s');
                            echo "Error #172: $date<br>\n";
			    echo "Error in call to countTableQuery from individual_search.php<br>\n";
			    echo "$num_of_indivs<br><br>\n";
			    echo "Please email the above error using the Comments/Help/Support link on the \n";
			    echo "left navigation bar.\n";
			    echo "</form>\n";
			    echo "</body></html>\n";
			    $ret_val = disconnect();
			    exit;
		          }#end error in call to countTableQuery

                        #if ($num_of_indivs > $max_records_to_print)
                        #  {
                        #    echo "Your search returned $num_of_indivs individuals.<br>\n";
                        #    tooManyIndividuals($indiv_table_id_term);
                        #    $ret_val = disconnect();
                        #    exit;
                        #  }#end if more than max to print

		        if ($num_of_indivs > ($max_records_to_print_per_page * 5))
                          {
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                            $indiv_table_id_array = distinctTableQuery('individual_table_id','individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in','all',$order_by);
                            if (!is_array($indiv_table_id_array))
                              {
                                $date = date('Y-m-d H:i:s');
			        echo "Error #173: $date<br>\n";
			        echo "Error in call to distincTableQuery from individual_search.php<br>\n";
			        echo "$indiv_table_id_array<br><br>\n";
			        echo "Please email the above error using the Comments/Help/Support link on the \n";
			        echo "left navigation bar.\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if error call to distinctTableQuery
                            $all_indiv_table_id_term = join($indiv_table_id_array,',');
                            unset($indiv_table_id_array);

                            moreThanFivePages($all_indiv_table_id_term);
                            unset($all_indiv_table_id_term);
                          }#end if more than 5 pages returned

		        if ($num_of_indivs > $max_records_to_print_per_page)
		          {
			    $indiv_multiple_pages = 1;
                            $from                 = "0";
                            $to                   = $max_records_to_print_per_page - 1;
                            $range                = "$from"."-"."$to";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
			    $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in',$range,$order_by);
			    if (!is_array($indiv_rec_list))
			      {
			        $date = date('Y-m-d H:i:s');
			        echo "Error #174: $date<br>\n";
			        echo "Error in call to tableQuery from individual_search.php<br>\n";
			        echo "$indiv_rec_list<br><br>\n";
			        echo "Please email the above error using the Comments/Help/Support link on the \n";
			        echo "left navigation bar.\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if (!is_array(indiv_rec_list))
                            if (sizeof($indiv_rec_list) == '0')
			      {
			        echo "<center>\n";
			        echo "Your search of the Phenotype Value Table did not yield any individuals.<br>\n";
			        echo "Please try your search again with different search criteria.<br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
			        echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
			        echo "</center>\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if (sizeof(indiv_rec_list) == '0')
			    $final_function_call   = 'tableQuery';
			    $final_table_name      = 'individual_table';
			    $final_field_list      = $field_list_array;
			    $final_term            = $indiv_table_id_term;
			    $final_mode            = 'in';
			    $final_order_by        = $order_by;
                            $last_record_retrieved = $max_records_to_print_per_page;
                          }#end if more than a single page
                        else #only a single page
		          {
			    $indiv_multiple_pages = 0;
                            $range                = "all";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                            $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in',$range,$order_by);
		            if (!is_array($indiv_rec_list))
                              {
			        $date = date('Y-m-d H:i:s');
		                echo "Error #175: $date<br>\n";
		                echo "Error in call to tableQuery from individual_search.php<br>\n";
		                echo "$indiv_rec_list<br><br>\n";
		                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (!is_array(indiv_rec_list))
		            if (sizeof($indiv_rec_list) == '0')
                              {
                                echo "<center>\n";
		                echo "Your search of the Phenotype Value Table did not yield any individuals.<br>\n";
		                echo "Please try a new search with different search criteria.<br><br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (sizeof(indiv_rec_list) == '0')
			  }#end else only a single page
                      }#end else sizeof(field_list) > '1'
		   }#end if (table_name == 'phenotype_value_table')

                 elseif ($table_name == 'age_group_table')
                   {
                    if (sizeof($field_list) == '1')
                      {
                        $num_of_modes = sizeof($mode);
                        for ($i = '0'; $i < $num_of_modes; $i++)
                          {
                            if ($mode[$i] != 'Select Type of Search')
                              {
                                $search_term = $term[$i];
                                $search_mode = $mode[$i];
                              }
                          }#end determine which term and mode to use

                        $age_group_rec_list = tableQuery($table_name,$database_id,$field_list,$search_term,$search_mode,'all');
                        if (!is_array($age_group_rec_list))
                          {
			    $date = date('Y-m-d H:i:s');
                            echo "Error #176: $date<br>\n";
                            echo "Error in call to tableQuery from individual_search.php<br>\n";
                            echo "$age_group_rec_list<br><br>\n";
                            echo "Please email the above error using The Comments/Help/Support link on the \n";
		            echo "left navigation bar.\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
                          }#end error in call to tableQuery
                        if (sizeof($age_group_rec_list) == '0')
                          {
                            echo "<center>\n";
		            echo "Your search of the Age Group Table did not yield any individuals.<br>\n";
		            echo "Please try a new search with different search criteria.<br><br>\n";
			    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		            echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                            echo "</center>\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
                          }#end if sizeof(rec_list) == '0'

			$field_list_array = array('phenotype_name');
			$phenotype_id_array = distinctTableQuery('phenotype_id','phenotype_table',$database_id,$field_list_array,'age','equal','all');
			if (!is_array($phenotype_id_array))
			  {
			    $date = date('Y-m-d H:i:s');
                            echo "Error #177: $date<br>\n";
                            echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
                            echo "$age_group_rec_list<br><br>\n";
                            echo "Please email the above error using The Comments/Help/Support link on the \n";
		            echo "left navigation bar.\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
                          }#end error in call to distinctTableQuery
			if (sizeof($phenotype_id_array) == '0')
			  {
			    echo "<center>\n";
                            echo "Cannot execute your query of the Age Group Table for individuals.<br>\n";
			    echo "The reason for this is that there is no 'age' phenotype defined in the database.<br>\n";
			    echo "Therefore cannot find individuals whose ages fall within the defined Age Groups.<br>\n";
			    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		            echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                            echo "</center>\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
                          }#end if no age phenotype
			elseif(sizeof($phenotype_id_array) == 1) {$age_phenotype_id = $phenotype_id_array[0];}
			else
			  {
			    $date = date('Y-m-d H:i:s');
			    echo "Error #178: $date<br>\n";
			    echo "User wanted to search for individuals based upon age group criteria, but when query the phenotype \n";
			    echo "table for the phenotype id of the 'age' phenotype multiple records were returned.<br><br>\n";
			    echo "Please email the above error using the Comments/Help/Support link on the \n";
			    echo "left navigation bar.\n";
			    echo "</form>\n";
			    echo "</body></html>\n";
			    $ret_val = disconnect();
			    exit;
			  }#end error in data integrity

                        $indiv_table_id_array = array();
			foreach ($age_group_rec_list as $age_group_rec)
			  {
			    $min_age = $age_group_rec['age_group_min_age'];
			    $max_age = $age_group_rec['age_group_max_age'];
			    $nationality = $age_group_rec['age_group_nationality'];

			    $query_min_age = $min_age - 1;
			    $query_max_age = $max_age + 1;
			    $query_field_list = array('phenotype_id','phenotype_value','phenotype_value');
			    $query_term_array = array($age_phenotype_id,$query_min_age,$query_max_age);
			    $query_mode_array = array('equal','greater_than','less_than');

			    $field_list_array = array('nationality');
			    $nat_indiv_table_id_array = distinctTableJoin('individual_table_id','pedigree_table','individual_table',$database_id,$field_list_array,$nationality,'equal','all');
			    if (!is_array($nat_indiv_table_id_array))
			      {
				$date = date('Y-m-d H:i:s');
				echo "Error #179: $date<br>\n";
				echo "Error in call to distinctTableJoin from individual_search.php<br>\n";
				echo "$nat_indiv_table_id_array<br><br>\n";
				echo "Please email the above error using The Comments/Help/Support link on the \n";
				echo "left navigation bar.\n";
				echo "</form>\n";
				echo "</body></html>\n";
				$ret_val = disconnect();
				exit;
			      }#end error in call to distinctTableJoin
			    if (sizeof($nat_indiv_table_id_array) > '0')
			      {
				$nat_indiv_table_id_term = join($nat_indiv_table_id_array,',');
				unset($nat_indiv_table_id_array);
				$query_field_list[] = 'individual_table_id';
				$query_term_array[] = $nat_indiv_table_id_term;
				$query_mode_array[] = 'in';

				$age_indiv_table_id_array = distinctCompoundTableQuery('individual_table_id','quantitative_phenotype_value_table',$database_id,$query_field_list,$query_term_array,$query_mode_array,'and','all');
				if (!is_array($age_indiv_table_id_array))
				  {
				    $date = date('Y-m-d H:i:s');
				    echo "Error #180: $date<br>\n";
				    echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
				    echo "$age_indiv_table_id_array<br><br>\n";
				    echo "Please email the above error using The Comments/Help/Support link on the \n";
				    echo "left navigation bar.\n";
				    echo "</form>\n";
				    echo "</body></html>\n";
				    $ret_val = disconnect();
				    exit;
				  }#end error in call to distinctCompoundTableQuery
				if (sizeof($age_indiv_table_id_array) > '0')
				  {
				    foreach ($age_indiv_table_id_array as $age_indiv_table_id)
                                      {
                                        if (!in_array($age_indiv_table_id,$indiv_table_id_array)){$indiv_table_id_array[] = $age_indiv_table_id;}
				      }#end for each indiv table id from query
				  }#end if indiv table ids returned from query
				unset($age_indiv_table_id_array);
			      }#end if individuals with nationality
			    unset($query_field_list,$query_term_array,$query_mode_array);
			  }#end foreach age group returned from query
			unset($age_group_rec_list);

			if (sizeof($indiv_table_id_array) == '0')
                          {
                            echo "<center>\n";
		            echo "Your search of the Age Group Table did not yield any individuals.<br>\n";
		            echo "Please try a new search with different search criteria.<br><br>\n";
			    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		            echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                            echo "</center>\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
                          }#end if sizeof(rec_list) == '0'
                        $indiv_table_id_term = join($indiv_table_id_array,',');
			unset($indiv_table_id_array);

                        $field_list_array = array('individual_table_id');
			$num_of_indivs = countTableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in');
			if (!preg_match('/^\d+$/',$num_of_indivs))
                          {
                            $date = date('Y-m-d H:i:s');
                            echo "Error #181: $date<br>\n";
			    echo "Error in call to countTableQuery from individual_search.php<br>\n";
			    echo "$num_of_indivs<br><br>\n";
			    echo "Please email the above error using the Comments/Help/Support link on the \n";
			    echo "left navigation bar.\n";
			    echo "</form>\n";
			    echo "</body></html>\n";
			    $ret_val = disconnect();
			    exit;
		          }#end error in call to countTableQuery

                        #if ($num_of_indivs > $max_records_to_print)
                        #  {
                        #    echo "Your search returned $num_of_indivs individuals.<br>\n";
                        #    tooManyIndividuals($indiv_table_id_term);
                        #    $ret_val = disconnect();
                        #    exit;
                        #  }#end if more than max to print

		        if ($num_of_indivs > ($max_records_to_print_per_page * 5))
                          {
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                            $indiv_table_id_array = distinctTableQuery('individual_table_id','individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in','all',$order_by);
                            if (!is_array($indiv_table_id_array))
                              {
                                $date = date('Y-m-d H:i:s');
			        echo "Error #182: $date<br>\n";
			        echo "Error in call to distincTableQuery from individual_search.php<br>\n";
			        echo "$indiv_table_id_array<br><br>\n";
			        echo "Please email the above error using the Comments/Help/Support link on the \n";
			        echo "left navigation bar.\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if error call to distinctTableQuery
                            $all_indiv_table_id_term = join($indiv_table_id_array,',');
                            unset($indiv_table_id_array);

                            moreThanFivePages($all_indiv_table_id_term);
                            unset($all_indiv_table_id_term);
                          }#end if more than 5 pages returned

		        if ($num_of_indivs > $max_records_to_print_per_page)
		          {
			    $indiv_multiple_pages = 1;
                            $from                 = "0";
                            $to                   = $max_records_to_print_per_page - 1;
                            $range                = "$from"."-"."$to";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
			    $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in',$range,$order_by);
			    if (!is_array($indiv_rec_list))
			      {
			        $date = date('Y-m-d H:i:s');
			        echo "Error #183: $date<br>\n";
			        echo "Error in call to tableQuery from individual_search.php<br>\n";
			        echo "$indiv_rec_list<br><br>\n";
			        echo "Please email the above error using the Comments/Help/Support link on the \n";
			        echo "left navigation bar.\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if (!is_array(indiv_rec_list))
                            if (sizeof($indiv_rec_list) == '0')
			      {
			        echo "<center>\n";
			        echo "Your search of the Age Group Table did not yield any individuals.<br>\n";
			        echo "Please try your search again with different search criteria.<br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
			        echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
			        echo "</center>\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if (sizeof(indiv_rec_list) == '0')
			    $final_function_call   = 'tableQuery';
			    $final_table_name      = 'individual_table';
			    $final_field_list      = $field_list_array;
			    $final_term            = $indiv_table_id_term;
			    $final_mode            = 'in';
			    $final_order_by        = $order_by;
                            $last_record_retrieved = $max_records_to_print_per_page;
                          }#end if more than a single page
                        else #only a single page
		          {
			    $indiv_multiple_pages = 0;
                            $range                = "all";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                            $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in',$range,$order_by);
		            if (!is_array($indiv_rec_list))
                              {
			        $date = date('Y-m-d H:i:s');
		                echo "Error #184: $date<br>\n";
		                echo "Error in call to tableQuery from individual_search.php<br>\n";
		                echo "$indiv_rec_list<br><br>\n";
		                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (!is_array(indiv_rec_list))
		            if (sizeof($indiv_rec_list) == '0')
                              {
                                echo "<center>\n";
		                echo "Your search of the Age Group Table did not yield any individuals.<br>\n";
		                echo "Please try a new search with different search criteria.<br><br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (sizeof(indiv_rec_list) == '0')
			  }#end else only a single page
                      }#end if sizeof(field_list) == '1'
                    else #sizeof(field_list) > '1'
                      {
                        $term_array = array();
                        $mode_array = array();
                        $num_of_fields = sizeof($field_list);
                        $num_of_modes  = sizeof($mode);
                        for ($i='0'; $i<$num_of_fields; $i++)
                          {
                            $place_on_field_list = ($i + 1);
                            $num_of_mode_seen = '0';
                            for ($j='0'; $j<$num_of_modes; $j++)
                              {
                                if ($mode[$j] != 'Select Type of Search')
                                  {
                                    $num_of_mode_seen = ($num_of_mode_seen + 1);
                                    if ($place_on_field_list == $num_of_mode_seen)
                                      {
                                        $term_array[] = $term[$j];
                                        $mode_array[] = $mode[$j];
                                      }#end if right place on list
                                  }#end if real mode
                              }#end foreach mode
                          }#end build search queries

                        $age_group_rec_list = compoundTableQuery($table_name,$database_id,$field_list,$term_array,$mode_array,$join,'all');
                        if (!is_array($age_group_rec_list))
                          {
			    $date = date('Y-m-d H:i:s');
                            echo "Error #185: $date<br>\n";
                            echo "Error in call to compoundTableQuery from individual_search.php<br>\n";
                            echo "$age_group_rec_list<br><br>\n";
                            echo "Please email the above error using The Comments/Help/Support link on the \n";
		            echo "left navigation bar.\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
                          }
                        if (sizeof($age_group_rec_list) == '0')
                          {
                            echo "<center>\n";
		            echo "Your search of the Age Group Table did not yield any individuals.<br>\n";
		            echo "Please try a new search with different search criteria.<br><br>\n";
			    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		            echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                            echo "</center>\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
                          }#end if no records

                        $field_list_array = array('phenotype_name');
			$phenotype_id_array = distinctTableQuery('phenotype_id','phenotype_table',$database_id,$field_list_array,'age','equal','all');
			if (!is_array($phenotype_id_array))
			  {
			    $date = date('Y-m-d H:i:s');
                            echo "Error #186: $date<br>\n";
                            echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
                            echo "$age_group_rec_list<br><br>\n";
                            echo "Please email the above error using The Comments/Help/Support link on the \n";
		            echo "left navigation bar.\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
                          }#end error in call to distinctTableQuery
			if (sizeof($phenotype_id_array) == '0')
			  {
			    echo "<center>\n";
                            echo "Cannot execute your query of the Age Group Table for individuals.<br>\n";
			    echo "The reason for this is that there is no 'age' phenotype defined in the database.<br>\n";
			    echo "Therefore cannot find individuals whose ages fall within the defined Age Groups.<br>\n";
			    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		            echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                            echo "</center>\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
                          }#end if no age phenotype
			elseif(sizeof($phenotype_id_array) == 1) {$age_phenotype_id = $phenotype_id_array[0];}
			else
			  {
			    $date = date('Y-m-d H:i:s');
			    echo "Error #187: $date<br>\n";
			    echo "User wanted to search for individuals based upon age group criteria, but when query the phenotype \n";
			    echo "table for the phenotype id of the 'age' phenotype multiple records were returned.<br><br>\n";
			    echo "Please email the above error using the Comments/Help/Support link on the \n";
			    echo "left navigation bar.\n";
			    echo "</form>\n";
			    echo "</body></html>\n";
			    $ret_val = disconnect();
			    exit;
			  }#end error in data integrity

                        $indiv_table_id_array = array();
			foreach ($age_group_rec_list as $age_group_rec)
			  {
			    $min_age = $age_group_rec['age_group_min_age'];
			    $max_age = $age_group_rec['age_group_max_age'];
			    $nationality = $age_group_rec['age_group_nationality'];

			    $query_min_age = $min_age - 1;
			    $query_max_age = $max_age + 1;
			    $query_field_list = array('phenotype_id','phenotype_value','phenotype_value');
			    $query_term_array = array($age_phenotype_id,$query_min_age,$query_max_age);
			    $query_mode_array = array('equal','greater_than','less_than');

			    $field_list_array = array('nationality');
			    $nat_indiv_table_id_array = distinctTableJoin('individual_table_id','pedigree_table','individual_table',$database_id,$field_list_array,$nationality,'equal','all');
			    if (!is_array($nat_indiv_table_id_array))
			      {
				$date = date('Y-m-d H:i:s');
				echo "Error #188: $date<br>\n";
				echo "Error in call to distinctTableJoin from individual_search.php<br>\n";
				echo "$nat_indiv_table_id_array<br><br>\n";
				echo "Please email the above error using The Comments/Help/Support link on the \n";
				echo "left navigation bar.\n";
				echo "</form>\n";
				echo "</body></html>\n";
				$ret_val = disconnect();
				exit;
			      }#end error in call to distinctTableJoin
			    if (sizeof($nat_indiv_table_id_array) > '0')
			      {
				$nat_indiv_table_id_term = join($nat_indiv_table_id_array,',');
				unset($nat_indiv_table_id_array);
				$query_field_list[] = 'individual_table_id';
				$query_term_array[] = $nat_indiv_table_id_term;
				$query_mode_array[] = 'in';

				$age_indiv_table_id_array = distinctCompoundTableQuery('individual_table_id','quantitative_phenotype_value_table',$database_id,$query_field_list,$query_term_array,$query_mode_array,'and','all');
				if (!is_array($age_indiv_table_id_array))
				  {
				    $date = date('Y-m-d H:i:s');
				    echo "Error #189: $date<br>\n";
				    echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
				    echo "$age_indiv_table_id_array<br><br>\n";
				    echo "Please email the above error using The Comments/Help/Support link on the \n";
				    echo "left navigation bar.\n";
				    echo "</form>\n";
				    echo "</body></html>\n";
				    $ret_val = disconnect();
				    exit;
				  }#end error in call to distinctCompoundTableQuery
				if (sizeof($age_indiv_table_id_array) > '0')
				  {
				    foreach ($age_indiv_table_id_array as $age_indiv_table_id)
                                      {
                                        if (!in_array($age_indiv_table_id,$indiv_table_id_array)){$indiv_table_id_array[] = $age_indiv_table_id;}
				      }#end for each indiv table id from query
				  }#end if indiv table ids returned from query
				unset($age_indiv_table_id_array);
			      }#end if individuals with nationality
			    unset($query_field_list,$query_term_array,$query_mode_array);
			  }#end foreach age group returned from query
			unset($age_group_rec_list);

			if (sizeof($indiv_table_id_array) == '0')
                          {
                            echo "<center>\n";
		            echo "Your search of the Age Group Table did not yield any individuals.<br>\n";
		            echo "Please try a new search with different search criteria.<br><br>\n";
			    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		            echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                            echo "</center>\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
                          }#end if sizeof(rec_list) == '0'
                        $indiv_table_id_term = join($indiv_table_id_array,',');
			unset($indiv_table_id_array);

                        $field_list_array = array('individual_table_id');
			$num_of_indivs = countTableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in');
			if (!preg_match('/^\d+$/',$num_of_indivs))
                          {
                            $date = date('Y-m-d H:i:s');
                            echo "Error #190: $date<br>\n";
			    echo "Error in call to countTableQuery from individual_search.php<br>\n";
			    echo "$num_of_indivs<br><br>\n";
			    echo "Please email the above error using the Comments/Help/Support link on the \n";
			    echo "left navigation bar.\n";
			    echo "</form>\n";
			    echo "</body></html>\n";
			    $ret_val = disconnect();
			    exit;
		          }#end error in call to countTableQuery

                        #if ($num_of_indivs > $max_records_to_print)
                        #  {
                        #    echo "Your search returned $num_of_indivs individuals.<br>\n";
                        #    tooManyIndividuals($indiv_table_id_term);
                        #    $ret_val = disconnect();
                        #    exit;
                        #  }#end if more than max to print

		        if ($num_of_indivs > ($max_records_to_print_per_page * 5))
                          {
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                            $indiv_table_id_array = distinctTableQuery('individual_table_id','individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in','all',$order_by);
                            if (!is_array($indiv_table_id_array))
                              {
                                $date = date('Y-m-d H:i:s');
			        echo "Error #191: $date<br>\n";
			        echo "Error in call to distincTableQuery from individual_search.php<br>\n";
			        echo "$indiv_table_id_array<br><br>\n";
			        echo "Please email the above error using the Comments/Help/Support link on the \n";
			        echo "left navigation bar.\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if error call to distinctTableQuery
                            $all_indiv_table_id_term = join($indiv_table_id_array,',');
                            unset($indiv_table_id_array);

                            moreThanFivePages($all_indiv_table_id_term);
                            unset($all_indiv_table_id_term);
                          }#end if more than 5 pages returned

		        if ($num_of_indivs > $max_records_to_print_per_page)
		          {
			    $indiv_multiple_pages = 1;
                            $from                 = "0";
                            $to                   = $max_records_to_print_per_page - 1;
                            $range                = "$from"."-"."$to";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
			    $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in',$range,$order_by);
			    if (!is_array($indiv_rec_list))
			      {
			        $date = date('Y-m-d H:i:s');
			        echo "Error #192: $date<br>\n";
			        echo "Error in call to tableQuery from individual_search.php<br>\n";
			        echo "$indiv_rec_list<br><br>\n";
			        echo "Please email the above error using the Comments/Help/Support link on the \n";
			        echo "left navigation bar.\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if (!is_array(indiv_rec_list))
                            if (sizeof($indiv_rec_list) == '0')
			      {
			        echo "<center>\n";
			        echo "Your search of the Age Group Table did not yield any individuals.<br>\n";
			        echo "Please try your search again with different search criteria.<br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
			        echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
			        echo "</center>\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if (sizeof(indiv_rec_list) == '0')
			    $final_function_call   = 'tableQuery';
			    $final_table_name      = 'individual_table';
			    $final_field_list      = $field_list_array;
			    $final_term            = $indiv_table_id_term;
			    $final_mode            = 'in';
			    $final_order_by        = $order_by;
                            $last_record_retrieved = $max_records_to_print_per_page;
                          }#end if more than a single page
                        else #only a single page
		          {
			    $indiv_multiple_pages = 0;
                            $range                = "all";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                            $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in',$range,$order_by);
		            if (!is_array($indiv_rec_list))
                              {
			        $date = date('Y-m-d H:i:s');
		                echo "Error #193: $date<br>\n";
		                echo "Error in call to tableQuery from individual_search.php<br>\n";
		                echo "$indiv_rec_list<br><br>\n";
		                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (!is_array(indiv_rec_list))
		            if (sizeof($indiv_rec_list) == '0')
                              {
                                echo "<center>\n";
		                echo "Your search of the Age Group Table did not yield any individuals.<br>\n";
		                echo "Please try a new search with different search criteria.<br><br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (sizeof(indiv_rec_list) == '0')
			  }#end else only a single page
                      }#end else sizeof(field_list) > '1'
                   }#end if table_name == age_group_table

                 elseif ($table_name == 'age_group_phenotype_percentile_link_table')
                   {
                    if (sizeof($field_list) == '1')
                      {
                        $num_of_modes = sizeof($mode);
                        for ($i = '0'; $i < $num_of_modes; $i++)
                          {
                            if ($mode[$i] != 'Select Type of Search')
                              {
                                $search_term = $term[$i];
                                $search_mode = $mode[$i];
                              }
                          }#end determine which term and mode to use

                        if (($field_list[0] == 'age_group_min_age') or
                            ($field_list[0] == 'age_group_max_age') or
                            ($field_list[0] == 'age_group_nationality')
                           )
                          {
                            $age_group_rec_list = tableQuery('age_group_table',$database_id,$field_list,$search_term,$search_mode,'all');
                            if (!is_array($age_group_rec_list))
                              {
				$date = date('Y-m-d H:i:s');
                                echo "Error #194: $date<br>\n";
                                echo "Error in call to tableQuery from individual_search.php<br>\n";
                                echo "$age_group_rec_list<br><br>\n";
                                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
                              }#end error in call to distinctTableQuery
                            if (sizeof($age_group_rec_list) == '0')
                              {
                                echo "<center>\n";
		                echo "Your search of the Age Group-Phenotype Percentile Link Table did not yield any individuals.<br>\n";
		                echo "Please try a new search with different search criteria.<br><br>\n";
				echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
                              }#end if sizeof(rec_list) == '0'

                            $field_list_array = array('phenotype_name');
			    $phenotype_id_array = distinctTableQuery('phenotype_id','phenotype_table',$database_id,$field_list_array,'age','equal','all');
			    if (!is_array($phenotype_id_array))
			      {
			        $date = date('Y-m-d H:i:s');
                                echo "Error #195: $date<br>\n";
                                echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
                                echo "$age_group_rec_list<br><br>\n";
                                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
                              }#end error in call to distinctTableQuery
			    if (sizeof($phenotype_id_array) == '0')
			      {
			        echo "<center>\n";
                                echo "Cannot execute your query of the Age Group-Phenotype Percentile Link Table for individuals.<br>\n";
			        echo "The reason for this is that there is no 'age' phenotype defined in the database.<br>\n";
			        echo "Therefore cannot find individuals whose ages fall within the defined Age Groups.<br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
                              }#end if no age phenotype
			    elseif(sizeof($phenotype_id_array) == 1) {$age_phenotype_id = $phenotype_id_array[0];}
			    else
			      {
			        $date = date('Y-m-d H:i:s');
			        echo "Error #196: $date<br>\n";
			        echo "User wanted to search for individuals based upon age group criteria, but when query the phenotype \n";
			        echo "table for the phenotype id of the 'age' phenotype multiple records were returned.<br><br>\n";
			        echo "Please email the above error using the Comments/Help/Support link on the \n";
			        echo "left navigation bar.\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end error in data integrity
			    unset($phenotype_id_array);

                            $indiv_table_id_array = array();
			    foreach ($age_group_rec_list as $age_group_rec)
			      {
			        $min_age = $age_group_rec['age_group_min_age'];
			        $max_age = $age_group_rec['age_group_max_age'];
			        $nationality = $age_group_rec['age_group_nationality'];

			        $query_min_age = $min_age - 1;
			        $query_max_age = $max_age + 1;
			        $query_field_list = array('phenotype_id','phenotype_value','phenotype_value');
			        $query_term_array = array($age_phenotype_id,$query_min_age,$query_max_age);
			        $query_mode_array = array('equal','greater_than','less_than');

			        $field_list_array = array('nationality');
			        $nat_indiv_table_id_array = distinctTableJoin('individual_table_id','pedigree_table','individual_table',$database_id,$field_list_array,$nationality,'equal','all');
			        if (!is_array($nat_indiv_table_id_array))
			          {
				    $date = date('Y-m-d H:i:s');
				    echo "Error #197: $date<br>\n";
				    echo "Error in call to distinctTableJoin from individual_search.php<br>\n";
				    echo "$nat_indiv_table_id_array<br><br>\n";
				    echo "Please email the above error using The Comments/Help/Support link on the \n";
				    echo "left navigation bar.\n";
				    echo "</form>\n";
				    echo "</body></html>\n";
				    $ret_val = disconnect();
				    exit;
			          }#end error in call to distinctTableJoin
			        if (sizeof($nat_indiv_table_id_array) > '0')
			          {
				    $nat_indiv_table_id_term = join($nat_indiv_table_id_array,',');
				    unset($nat_indiv_table_id_array);
				    $query_field_list[] = 'individual_table_id';
				    $query_term_array[] = $nat_indiv_table_id_term;
				    $query_mode_array[] = 'in';

				    $age_indiv_table_id_array = distinctCompoundTableQuery('individual_table_id','quantitative_phenotype_value_table',$database_id,$query_field_list,$query_term_array,$query_mode_array,'and','all');
				    if (!is_array($age_indiv_table_id_array))
				      {
				        $date = date('Y-m-d H:i:s');
				        echo "Error #198: $date<br>\n";
				        echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
				        echo "$age_indiv_table_id_array<br><br>\n";
				        echo "Please email the above error using The Comments/Help/Support link on the \n";
				        echo "left navigation bar.\n";
				        echo "</form>\n";
				        echo "</body></html>\n";
				        $ret_val = disconnect();
				        exit;
				      }#end error in call to distinctCompoundTableQuery
				    if (sizeof($age_indiv_table_id_array) > '0')
				      {
				        foreach ($age_indiv_table_id_array as $age_indiv_table_id)
                                          {
                                            if (!in_array($age_indiv_table_id,$indiv_table_id_array)){$indiv_table_id_array[] = $age_indiv_table_id;}
				          }#end for each indiv table id from query
				      }#end if indiv table ids returned from query
				    unset($age_indiv_table_id_array);
			          }#end if individuals with nationality
			        unset($query_field_list,$query_term_array,$query_mode_array);
			      }#end foreach age group returned from query
			    unset($age_group_rec_list);

			    if (sizeof($indiv_table_id_array) == '0')
                              {
                                echo "<center>\n";
		                echo "Your search of the Age Group-Phenotype Percentile Link Table did not yield any individuals.<br>\n";
		                echo "Please try a new search with different search criteria.<br><br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
                              }#end if sizeof(rec_list) == '0'
                            $indiv_table_id_term = join($indiv_table_id_array,',');
			    unset($indiv_table_id_array);
                          }#end if age_group_table field
                        elseif ($field_list[0] == 'phenotype_name')
                          {
                            $phenotype_id_array = distinctTableQuery('phenotype_id','phenotype_table',$database_id,$field_list,$search_term,$search_mode,'all');
                            if (!is_array($phenotype_id_array))
                              {
				$date = date('Y-m-d H:i:s');
                                echo "Error #199: $date<br>\n";
                                echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
                                echo "$phenotype_id_array<br><br>\n";
                                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
                              }#end error in call to distinctTableQuery
                            if (sizeof($phenotype_id_array) == '0')
                              {
                                echo "<center>\n";
		                echo "Your search of the Age Group-Phenotype Percentile Link Table did not yield any individuals.<br>\n";
		                echo "Please try a new search with different search criteria.<br><br>\n";
				echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
                              }#end if sizeof(rec_list) == '0'
                            $phenotype_id_term = join($phenotype_id_array,',');
			    unset($phenotype_id_array);

                            $field_list_array = array('phenotype_id');
                            $rec_list_1 = distinctTableQuery('individual_table_id','qualitative_phenotype_value_table',$database_id,$field_list_array,$phenotype_id_term,'in','all');
                            if (!is_array($rec_list_1))
                              {
				$date = date('Y-m-d H:i:s');
                                echo "Error #200: $date<br>\n";
                                echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
                                echo "$rec_list_1<br><br>\n";
                                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
                              }#end error in call to distinctTableQuery

                            $rec_list_2 = distinctTableQuery('individual_table_id','quantitative_phenotype_value_table',$database_id,$field_list_array,$phenotype_id_term,'in','all');
                            if (!is_array($rec_list_2))
                              {
				$date = date('Y-m-d H:i:s');
                                echo "Error #201: $date<br>\n";
                                echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
                                echo "$rec_list_2<br><br>\n";
                                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
                              }#end error in call to distinctTableQuery
                            if ((sizeof($rec_list_1) == '0') and (sizeof($rec_list_2) == '0'))
                              {
                                echo "<center>\n";
		                echo "Your search of the Age Group-Phenotype Percentile Link Table did not yield any individuals.<br>\n";
		                echo "Please try a new search with different search criteria.<br><br>\n";
				echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
                              }#end if sizeof(rec_list) == '0'
                            if ((sizeof($rec_list_1) > '0') and (sizeof($rec_list_2) == '0'))
                              { $indiv_table_id_term = join($rec_list_1,',');}
                            if ((sizeof($rec_list_2) > '0') and (sizeof($rec_list_1) == '0'))
                              { $indiv_table_id_term = join($rec_list_2,',');}
                            else
                              {
                                $indiv_table_id_term = join($rec_list_1,',');
                                $indiv_table_id_term.= ",";
                                $indiv_table_id_term.= join($rec_list_2,',');
                              }
			    unset($rec_list_1);
                            unset($rec_list_2);
                          }#end if phenotype_table field
                        else #age_group_phenotype_percentile_link_table fields
                          {
			    if ((preg_match('/_male_/',$field_list[0])) or (preg_match('/_female_/',$field_list[0])))#if searching on a phenotype value field
			      {
				$field_list_array = array('age_group_phenotype_percentile_link_id');
				$ag_pheno_rec_list = tableQuery($table_name,$database_id,$field_list_array,'_','wildcard','all');
				if (!is_array($ag_pheno_rec_list))
				  {
				    $date = date('Y-m-d H:i:s');
				    echo "Error #202: $date<br>\n";
				    echo "Error in call to tableQuery from individual_search.php<br>\n";
				    echo "$ag_pheno_rec_list<br><br>\n";
				    echo "Please email the above error using The Comments/Help/Support link on the \n";
				    echo "left navigation bar.\n";
				    echo "</form>\n";
				    echo "</body></html>\n";
				    $ret_val = disconnect();
				    exit;
                                  }#end error in call to distinctTableQuery
                                if (sizeof($ag_pheno_rec_list) == '0')
				  {
				    echo "<center>\n";
				    echo "Your search of the Age Group-Phenotype Percentile Link Table did not yield any individuals.<br>\n";
				    echo "Please try a new search with different search criteria.<br><br>\n";
				    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
				    echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
				    echo "</center>\n";
				    echo "</form>\n";
				    echo "</body></html>\n";
				    $ret_val = disconnect();
				    exit;
				  }#end if sizeof(rec_list) == '0'

                                $field_list_array = array('phenotype_name');
				$phenotype_id_array = distinctTableQuery('phenotype_id','phenotype_table',$database_id,$field_list_array,'age','equal','all');
				if (!is_array($phenotype_id_array))
				  {
				    $date = date('Y-m-d H:i:s');
				    echo "Error #203: $date<br>\n";
				    echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
				    echo "$age_group_rec_list<br><br>\n";
				    echo "Please email the above error using The Comments/Help/Support link on the \n";
				    echo "left navigation bar.\n";
				    echo "</form>\n";
				    echo "</body></html>\n";
				    $ret_val = disconnect();
				    exit;
				  }#end error in call to distinctTableQuery
			        if (sizeof($phenotype_id_array) == '0')
				  {
				    echo "<center>\n";
				    echo "Cannot execute your query of the Age Group-Phenotype Percentile Link Table for individuals.<br>\n";
				    echo "The reason for this is that there is no 'age' phenotype defined in the database.<br>\n";
				    echo "Therefore cannot find individuals whose ages fall within the defined Age Groups.<br>\n";
				    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
				    echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
				    echo "</center>\n";
				    echo "</form>\n";
				    echo "</body></html>\n";
				    $ret_val = disconnect();
				    exit;
				  }#end if no age phenotype
			        elseif(sizeof($phenotype_id_array) == 1) {$age_phenotype_id = $phenotype_id_array[0];}
			        else
				  {
				    $date = date('Y-m-d H:i:s');
				    echo "Error #204: $date<br>\n";
				    echo "Error in call to individual_search.php<br>\n";
				    echo "User wanted to search for individuals based upon age group criteria, but when query the phenotype \n";
				    echo "table for the phenotype id of the 'age' phenotype multiple records were returned.<br><br>\n";
				    echo "Please email the above error using the Comments/Help/Support link on the \n";
				    echo "left navigation bar.\n";
				    echo "</form>\n";
				    echo "</body></html>\n";
				    $ret_val = disconnect();
				    exit;
				  }#end error in data integrity
				unset($phenotype_id_array);

			        $indiv_table_id_array = array();
				foreach ($ag_pheno_rec_list as $ag_pheno_rec)
				  {
				    $age_group_id = $ag_pheno_rec['age_group_id'];
				    $phenotype_id = $ag_pheno_rec['phenotype_id'];

				    $field_list_array = array('age_group_id');
				    $age_group_rec_list = tableQuery('age_group_table',$database_id,$field_list_array,$age_group_id,'equal','all');
				    if (!is_array($age_group_rec_list))
				      {
					$date = date('Y-m-d H:i:s');
					echo "Error #205: $date<br>\n";
					echo "Error in call to tableQuery from individual_search.php<br>\n";
					echo "$age_group_rec_list<br><br>\n";
					echo "Please email the above error using The Comments/Help/Support link on the \n";
					echo "left navigation bar.\n";
					echo "</form>\n";
					echo "</body></html>\n";
					$ret_val = disconnect();
					exit;
				      }#end error in call to tableQuery
				    if (sizeof($age_group_rec_list) == 1) {$age_group_rec = $age_group_rec_list[0];}
				    else #error in data integrity
				      {
					$date = date('Y-m-d H:i:s');
					echo "Error #206: $date<br>\n";
					echo "Error in call to individual_search.php<br>\n";
					echo "User wanted to search for individuals based upon age group-phenotype percentile criteria.<br>\n";
					echo "Query returned age_group_phenotype_percentile_link_id $ag_pheno_rec[age_group_phenotype_percentile_link_id] \n";
					echo "which has age_group_id $age_group_id, but when query the age_group_table with that id ".sizeof($age_group_rec_list)." \n";
					echo "records were returned.<br><br>\n";
					echo "Please email the above error using the Comments/Help/Support link on the \n";
					echo "left navigation bar.\n";
					echo "</form>\n";
					echo "</body></html>\n";
					$ret_val = disconnect();
					exit;
				      }#end error in data integrity
				    $min_age = $age_group_rec['age_group_min_age'];
				    $max_age = $age_group_rec['age_group_max_age'];
				    $nationality = $age_group_rec['nationality'];
				    unset($age_group_rec,$age_group_rec_list);

				    $query_min_age = $min_age - 1;
				    $query_max_age = $max_age + 1;
				    $query_field_list = array('phenotype_id','phenotype_value','phenotype_value');
				    $query_term_array = array($age_phenotype_id,$query_min_age,$query_max_age);
				    $query_mode_array = array('equal','greater_than','less_than');
				    
				    $field_list_array = array('nationality');
				    $nat_ped_table_id_array = distinctTableQuery('pedigree_table_id','pedigree_table',$database_id,$field_list_array,$nationality,'equal','all');
				    if (!is_array($nat_ped_table_id_array))
				      {
					$date = date('Y-m-d H:i:s');
					echo "Error #207: $date<br>\n";
					echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
					echo "$nat_ped_table_id_array<br><br>\n";
					echo "Please email the above error using The Comments/Help/Support link on the \n";
					echo "left navigation bar.\n";
					echo "</form>\n";
					echo "</body></html>\n";
					$ret_val = disconnect();
					exit;
			              }#end error in call to distinctTableQuery
				    if (sizeof($nat_ped_table_id_array) > '0')
				      {
					$nat_ped_table_id_term = join($nat_ped_table_id_array,',');
					unset($nat_ped_table_id_array);

					$field_list_array  = array('pedigree_table_id','sex');
                                        $search_term_array = array($nat_ped_table_id_term);
                                        if (preg_match('/_male_/',$field_list[0]))   {$search_term_array[] = '1';}
                                        if (preg_match('/_female_/',$field_list[0])) {$search_term_array[] = '2';}
                                        $search_mode_array = array('in','equal');
                                        $sex_nat_indiv_table_id_array = distinctCompoundTableQuery('individual_table_id','individual_table',$database_id,$field_list_array,$search_term_array,$search_mode_array,'and','all');
                                        if (!is_array($sex_nat_indiv_table_id_array))
					  {
					    $date = date('Y-m-d H:i:s');
					    echo "Error #208: $date<br>\n";
					    echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
					    echo "$sex_nat_indiv_table_id_array<br><br>\n";
					    echo "Please email the above error using The Comments/Help/Support link on the \n";
					    echo "left navigation bar.\n";
					    echo "</form>\n";
					    echo "</body></html>\n";
					    $ret_val = disconnect();
					    exit;
					  }#end error in call to distinctCompoundTableQuery
					if (sizeof($sex_nat_indiv_table_id_array) > '0')
					  {
					    $sex_nat_indiv_table_id_term = join($sex_nat_indiv_table_id_array,',');
					    unset($sex_nat_indiv_table_id_array);
					    $query_field_list[] = 'individual_table_id';
					    $query_term_array[] = $sex_nat_indiv_table_id_term;
					    $query_mode_array[] = 'in';

					    $age_indiv_table_id_array = distinctCompoundTableQuery('individual_table_id','quantitative_phenotype_value_table',$database_id,$query_field_list,$query_term_array,$query_mode_array,'and','all');
					    if (!is_array($age_indiv_table_id_array))
					      {
						$date = date('Y-m-d H:i:s');
						echo "Error #209: $date<br>\n";
						echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
						echo "$age_indiv_table_id_array<br><br>\n";
						echo "Please email the above error using The Comments/Help/Support link on the \n";
						echo "left navigation bar.\n";
						echo "</form>\n";
						echo "</body></html>\n";
						$ret_val = disconnect();
						exit;
					      }#end error in call to distinctCompoundTableQuery
				            $age_indiv_table_id_term = join($age_indiv_table_id_array,',');
					    unset($age_indiv_table_id_array);

					    $query_field_list = array('individual_table_id','phenotype_id','phenotype_value');
					    $query_term_array = array($age_indiv_table_id_term,$phenotype_id,$ag_pheno_rec[$search_term]);
					    $query_mode_array = array('in','equal',$search_mode);
					    $indiv_ids = distinctCompoundTableQuery('individual_table_id','qualitative_phenotype_value_table',$databse_id,$query_field_list,$query_term_array,$query_mode_array,'and','all');
					    if (!is_array($indiv_ids))
					      {
						$date = date('Y-m-d H:i:s');
						echo "Error #210: $date<br>\n";
						echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
						echo "$indiv_ids<br><br>\n";
						echo "Please email the above error using The Comments/Help/Support link on the \n";
						echo "left navigation bar.\n";
						echo "</form>\n";
						echo "</body></html>\n";
						$ret_val = disconnect();
						exit;
					      }#end error in call to distinctCompoundTableQuery
					    if (sizeof($indiv_ids) > '0')
					      {
						$term = join($indiv_ids,',');
						$indiv_table_id_array[] = $term;
					      }

                                            $indiv_ids = distinctCompoundTableQuery('individual_table_id','quantitative_phenotype_value_table',$databse_id,$query_field_list,$query_term_array,$query_mode_array,'and','all');
					    if (!is_array($indiv_ids))
					      {
						$date = date('Y-m-d H:i:s');
						echo "Error #211: $date<br>\n";
						echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
						echo "$indiv_ids<br><br>\n";
						echo "Please email the above error using The Comments/Help/Support link on the \n";
						echo "left navigation bar.\n";
						echo "</form>\n";
						echo "</body></html>\n";
						$ret_val = disconnect();
						exit;
					      }#end error in call to distinctCompoundTableQuery
					    if (sizeof($indiv_ids) > '0')
					      {
						$term = join($indiv_ids,',');
						$indiv_table_id_array[] = $term;
					      }
					  }#end if individuals who meet sex and nationality requirements
				      }#end if have pedigrees who meet nationality requirement
				    unset($query_field_list,$query_term_array,$query_mode_array);
				  }#end foreach ag_pheno_rec_list
				unset($ag_pheno_rec,$ag_pheno_rec_list);

				if (sizeof($indiv_table_id_array) == '0')
				  {
				    echo "<center>\n";
				    echo "Your search of the Age Group-Phenotype Percentile Link Table did not yield any individuals.<br>\n";
				    echo "Please try a new search with different search criteria.<br><br>\n";
				    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
				    echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
				    echo "</center>\n";
				    echo "</form>\n";
				    echo "</body></html>\n";
				    $ret_val = disconnect();
				    exit;
				  }#end if sizeof(rec_list) == '0'
                                $indiv_table_id_term = join($indiv_table_id_array,',');
				unset($indiv_table_id_array);
			      }#end if search field was a phenotype value
			    else #searching on date last updated field
			      {
				$ag_pheno_rec_list = tableQuery($table_name,$database_id,$field_list,$search_term,$search_mode,'all');
				if (!is_array($ag_pheno_rec_list))
				  {
				    $date = date('Y-m-d H:i:s');
				    echo "Error #212: $date<br>\n";
				    echo "Error in call to tableQuery from individual_search.php<br>\n";
				    echo "$ag_pheno_rec_list<br><br>\n";
				    echo "Please email the above error using the Comments/Help/Support link on the \n";
				    echo "left navigation bar.\n";
				    echo "</form>\n";
				    echo "</body></html>\n";
				    $ret_val = disconnect();
				    exit;
				  }#end error in call to tableQuery
				if (sizeof($ag_pheno_rec_list) == '0')
				  {
				    echo "<center>\n";
				    echo "Your search of the Age Group-Phenotype Percentile Link Table did not yield any individuals.<br>\n";
				    echo "Please try a new search with different search criteria.<br><br>\n";
				    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
				    echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
				    echo "</center>\n";
				    echo "</form>\n";
				    echo "</body></html>\n";
				    $ret_val = disconnect();
				    exit;
				  }#end if sizeof(rec_list) == '0'

                                $field_list_array = array('phenotype_name');
				$phenotype_id_array = distinctTableQuery('phenotype_id','phenotype_table',$database_id,$field_list_array,'age','equal','all');
				if (!is_array($phenotype_id_array))
				  {
				    $date = date('Y-m-d H:i:s');
				    echo "Error #213: $date<br>\n";
				    echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
				    echo "$age_group_rec_list<br><br>\n";
				    echo "Please email the above error using The Comments/Help/Support link on the \n";
				    echo "left navigation bar.\n";
				    echo "</form>\n";
				    echo "</body></html>\n";
				    $ret_val = disconnect();
				    exit;
				  }#end error in call to distinctTableQuery
			        if (sizeof($phenotype_id_array) == '0')
				  {
				    echo "<center>\n";
				    echo "Cannot execute your query of the Age Group-Phenotype Percentile Link Table for individuals.<br>\n";
				    echo "The reason for this is that there is no 'age' phenotype defined in the database.<br>\n";
				    echo "Therefore cannot find individuals whose ages fall within the defined Age Groups.<br>\n";
				    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
				    echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
				    echo "</center>\n";
				    echo "</form>\n";
				    echo "</body></html>\n";
				    $ret_val = disconnect();
				    exit;
				  }#end if no age phenotype
			        elseif(sizeof($phenotype_id_array) == 1) {$age_phenotype_id = $phenotype_id_array[0];}
			        else
				  {
				    $date = date('Y-m-d H:i:s');
				    echo "Error #214: $date<br>\n";
				    echo "Error in call to individual_search.php<br>\n";
				    echo "User wanted to search for individuals based upon age group criteria, but when query the phenotype \n";
				    echo "table for the phenotype id of the 'age' phenotype multiple records were returned.<br><br>\n";
				    echo "Please email the above error using the Comments/Help/Support link on the \n";
				    echo "left navigation bar.\n";
				    echo "</form>\n";
				    echo "</body></html>\n";
				    $ret_val = disconnect();
				    exit;
				  }#end error in data integrity
				unset($phenotype_id_array);

			        $indiv_table_id_array = array();
				foreach ($ag_pheno_rec_list as $ag_pheno_rec)
				  {
				    $age_group_id = $ag_pheno_rec['age_group_id'];
				    $phenotype_id = $ag_pheno_rec['phenotype_id'];

				    $field_list_array = array('age_group_id');
				    $age_group_rec_list = tableQuery('age_group_table',$database_id,$field_list_array,$age_group_id,'equal','all');
				    if (!is_array($age_group_rec_list))
				      {
					$date = date('Y-m-d H:i:s');
					echo "Error #215: $date<br>\n";
					echo "Error in call to tableQuery from individual_search.php<br>\n";
					echo "$age_group_rec_list<br><br>\n";
					echo "Please email the above error using The Comments/Help/Support link on the \n";
					echo "left navigation bar.\n";
					echo "</form>\n";
					echo "</body></html>\n";
					$ret_val = disconnect();
					exit;
				      }#end error in call to tableQuery
				    if (sizeof($age_group_rec_list) == 1) {$age_group_rec = $age_group_rec_list[0];}
				    else #error in data integrity
				      {
					$date = date('Y-m-d H:i:s');
					echo "Error #216: $date<br>\n";
					echo "Error in call to individual_search.php<br>\n";
					echo "User wanted to search for individuals based upon age group-phenotype percentile criteria.<br>\n";
					echo "Query returned age_group_phenotype_percentile_link_id $ag_pheno_rec[age_group_phenotype_percentile_link_id] \n";
					echo "which has age_group_id $age_group_id, but when query the age_group_table with that id ".sizeof($age_group_rec_list)." \n";
					echo "records were returned.<br><br>\n";
					echo "Please email the above error using the Comments/Help/Support link on the \n";
					echo "left navigation bar.\n";
					echo "</form>\n";
					echo "</body></html>\n";
					$ret_val = disconnect();
					exit;
				      }#end error in data integrity
				    $min_age = $age_group_rec['age_group_min_age'];
				    $max_age = $age_group_rec['age_group_max_age'];
				    $nationality = $age_group_rec['nationality'];
				    unset($age_group_rec,$age_group_rec_list);

				    $query_min_age = $min_age - 1;
				    $query_max_age = $max_age + 1;
				    $query_field_list = array('phenotype_id','phenotype_value','phenotype_value');
				    $query_term_array = array($age_phenotype_id,$query_min_age,$query_max_age);
				    $query_mode_array = array('equal','greater_than','less_than');
				    
				    $field_list_array = array('nationality');
				    $nat_indiv_table_id_array = distinctTableJoin('individual_table_id','pedigree_table','individual_table',$database_id,$field_list_array,$nationality,'equal','all');
				    if (!is_array($nat_indiv_table_id_array))
				      {
					$date = date('Y-m-d H:i:s');
					echo "Error #217: $date<br>\n";
					echo "Error in call to distinctTableJoin from individual_search.php<br>\n";
					echo "$nat_indiv_table_id_array<br><br>\n";
					echo "Please email the above error using The Comments/Help/Support link on the \n";
					echo "left navigation bar.\n";
					echo "</form>\n";
					echo "</body></html>\n";
					$ret_val = disconnect();
					exit;
				      }#end error in call to distinctTableJoin
				    if (sizeof($nat_indiv_table_id_array) > '0')
				      {
					$nat_indiv_table_id_term = join($nat_indiv_table_id_array,',');
					unset($nat_indiv_table_id_array);
					$query_field_list[] = 'individual_table_id';
					$query_term_array[] = $nat_indiv_table_id_term;
					$query_mode_array[] = 'in';

					$age_indiv_table_id_array = distinctCompoundTableQuery('individual_table_id','quantitative_phenotype_value_table',$database_id,$query_field_list,$query_term_array,$query_mode_array,'and','all');
					if (!is_array($age_indiv_table_id_array))
					  {
					    $date = date('Y-m-d H:i:s');
					    echo "Error #218: $date<br>\n";
					    echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
					    echo "$age_indiv_table_id_array<br><br>\n";
					    echo "Please email the above error using The Comments/Help/Support link on the \n";
					    echo "left navigation bar.\n";
					    echo "</form>\n";
					    echo "</body></html>\n";
					    $ret_val = disconnect();
					    exit;
					  }#end error in call to distinctCompoundTableQuery
				        $age_indiv_table_id_term = join($age_indiv_table_id_array,',');
					unset($age_indiv_table_id_array);

					$query_field_list = array('individual_table_id','phenotype_id');
					$query_term_array = array($age_indiv_table_id_term,$phenotype_id);
					$query_mode_array = array('in','equal');
					$indiv_ids = distinctCompoundTableQuery('individual_table_id','qualitative_phenotype_value_table',$databse_id,$query_field_list,$query_term_array,$query_mode_array,'and','all');
					if (!is_array($indiv_ids))
					  {
					    $date = date('Y-m-d H:i:s');
					    echo "Error #219: $date<br>\n";
					    echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
					    echo "$indiv_ids<br><br>\n";
					    echo "Please email the above error using The Comments/Help/Support link on the \n";
					    echo "left navigation bar.\n";
					    echo "</form>\n";
					    echo "</body></html>\n";
					    $ret_val = disconnect();
					    exit;
					  }#end error in call to distinctCompoundTableQuery
					if (sizeof($indiv_ids) > '0')
					  {
					    $term = join($indiv_ids,',');
					    $indiv_table_id_array[] = $term;
					  }

                                        $indiv_ids = distinctCompoundTableQuery('individual_table_id','quantitative_phenotype_value_table',$databse_id,$query_field_list,$query_term_array,$query_mode_array,'and','all');
					if (!is_array($indiv_ids))
					  {
					    $date = date('Y-m-d H:i:s');
					    echo "Error #220: $date<br>\n";
					    echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
					    echo "$indiv_ids<br><br>\n";
					    echo "Please email the above error using The Comments/Help/Support link on the \n";
					    echo "left navigation bar.\n";
					    echo "</form>\n";
					    echo "</body></html>\n";
					    $ret_val = disconnect();
					    exit;
					  }#end error in call to distinctCompoundTableQuery
					if (sizeof($indiv_ids) > '0')
					  {
					    $term = join($indiv_ids,',');
					    $indiv_table_id_array[] = $term;
					  }
				      }#end if have individuals who meet nationality requirement
				    unset($query_field_list,$query_term_array,$query_mode_array);
				  }#end foreach ag_pheno_rec_list
				unset($ag_pheno_rec,$ag_pheno_rec_list);

				if (sizeof($indiv_table_id_array) == '0')
				  {
				    echo "<center>\n";
				    echo "Your search of the Age Group-Phenotype Percentile Link Table did not yield any individuals.<br>\n";
				    echo "Please try a new search with different search criteria.<br><br>\n";
				    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
				    echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
				    echo "</center>\n";
				    echo "</form>\n";
				    echo "</body></html>\n";
				    $ret_val = disconnect();
				    exit;
				  }#end if sizeof(rec_list) == '0'
                                $indiv_table_id_term = join($indiv_table_id_array,',');
				unset($indiv_table_id_array);
			      }#end else searching last updated field
                          }#end else age_group_phenotype_percentile_link_table fields

                        $field_list_array = array('individual_table_id');
			$num_of_indivs = countTableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in');
			if (!preg_match('/^\d+$/',$num_of_indivs))
                          {
                            $date = date('Y-m-d H:i:s');
                            echo "Error #221: $date<br>\n";
			    echo "Error in call to countTableQuery from individual_search.php<br>\n";
			    echo "$num_of_indivs<br><br>\n";
			    echo "Please email the above error using the Comments/Help/Support link on the \n";
			    echo "left navigation bar.\n";
			    echo "</form>\n";
			    echo "</body></html>\n";
			    $ret_val = disconnect();
			    exit;
		          }#end error in call to countTableQuery

                        #if ($num_of_indivs > $max_records_to_print)
                        #  {
                        #    echo "Your search returned $num_of_indivs individuals.<br>\n";
                        #    tooManyIndividuals($indiv_table_id_term);
                        #    $ret_val = disconnect();
                        #    exit;
                        #  }#end if more than max to print

		        if ($num_of_indivs > ($max_records_to_print_per_page * 5))
                          {
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                            $indiv_table_id_array = distinctTableQuery('individual_table_id','individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in','all',$order_by);
                            if (!is_array($indiv_table_id_array))
                              {
                                $date = date('Y-m-d H:i:s');
			        echo "Error #222: $date<br>\n";
			        echo "Error in call to distincTableQuery from individual_search.php<br>\n";
			        echo "$indiv_table_id_array<br><br>\n";
			        echo "Please email the above error using the Comments/Help/Support link on the \n";
			        echo "left navigation bar.\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if error call to distinctTableQuery
                            $all_indiv_table_id_term = join($indiv_table_id_array,',');
                            unset($indiv_table_id_array);

                            moreThanFivePages($all_indiv_table_id_term);
                            unset($all_indiv_table_id_term);
                          }#end if more than 5 pages returned

		        if ($num_of_indivs > $max_records_to_print_per_page)
		          {
			    $indiv_multiple_pages = 1;
                            $from                 = "0";
                            $to                   = $max_records_to_print_per_page - 1;
                            $range                = "$from"."-"."$to";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
			    $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in',$range,$order_by);
			    if (!is_array($indiv_rec_list))
			      {
			        $date = date('Y-m-d H:i:s');
			        echo "Error #223: $date<br>\n";
			        echo "Error in call to tableQuery from individual_search.php<br>\n";
			        echo "$indiv_rec_list<br><br>\n";
			        echo "Please email the above error using the Comments/Help/Support link on the \n";
			        echo "left navigation bar.\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if (!is_array(indiv_rec_list))
                            if (sizeof($indiv_rec_list) == '0')
			      {
			        echo "<center>\n";
			        echo "Your search of the Age Group-Phenotype Percentile Link Table did not yield any individuals.<br>\n";
			        echo "Please try your search again with different search criteria.<br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
			        echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
			        echo "</center>\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if (sizeof(indiv_rec_list) == '0')
			    $final_function_call   = 'tableQuery';
			    $final_table_name      = 'individual_table';
			    $final_field_list      = $field_list_array;
			    $final_term            = $indiv_table_id_term;
			    $final_mode            = 'in';
			    $final_order_by        = $order_by;
                            $last_record_retrieved = $max_records_to_print_per_page;
                          }#end if more than a single page
                        else #only a single page
		          {
			    $indiv_multiple_pages = 0;
                            $range                = "all";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                            $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in',$range,$order_by);
		            if (!is_array($indiv_rec_list))
                              {
			        $date = date('Y-m-d H:i:s');
		                echo "Error #224: $date<br>\n";
		                echo "Error in call to tableQuery from individual_search.php<br>\n";
		                echo "$indiv_rec_list<br><br>\n";
		                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (!is_array(indiv_rec_list))
		            if (sizeof($indiv_rec_list) == '0')
                              {
                                echo "<center>\n";
		                echo "Your search of the Age Group-Phenotype Percentile Link Table did not yield any individuals.<br>\n";
		                echo "Please try a new search with different search criteria.<br><br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (sizeof(indiv_rec_list) == '0')
			  }#end else only a single page
                      }#end if sizeof(field_list) == '1'
                    else #sizeof(field_list) > '1'
                      {
                        $age_group_table_field_list = array();
                        $age_group_table_term_array = array();
                        $age_group_table_mode_array = array();
                        $phenotype_table_field_list = array();
                        $phenotype_table_search_term = "";
                        $phenotype_table_search_mode = "";
			$phenotype_percent_field_list = array();
			$phenotype_percent_term_array = array();
			$phenotype_percent_mode_array = array();
                        $final_query_field_list      = array();
                        $final_query_term_array      = array();
                        $final_query_mode_array      = array();
                        $num_of_fields               = sizeof($field_list);
                        $num_of_modes                = sizeof($mode);
                        for ($i = '0'; $i < $num_of_fields; $i++)
                          {
                            if (($field_list[$i] == 'age_group_min_age') or
                                ($field_list[$i] == 'age_group_max_age') or
                                ($field_list[$i] == 'age_group_nationality')
                               )
                              {
                                $place_on_field_list = ($i + 1);
                                $age_group_table_field_list[] = $field_list[$i];
                                $num_of_mode_seen = '0';
                                for ($j='0'; $j<$num_of_modes; $j++)
                                  {
                                    if ($mode[$j] != 'Select Type of Search')
                                      {
                                        $num_of_mode_seen = ($num_of_mode_seen + 1);
                                        if ($place_on_field_list == $num_of_mode_seen)
                                          {
                                            $age_group_table_term_array[] = $term[$j];
                                            $age_group_table_mode_array[] = $mode[$j];
                                          }#end if right place on list
                                      }#end if real mode
                                  }#end foreach mode
                              }
                            elseif ($field_list[$i] == 'phenotype_name')
                              {
                                $place_on_field_list = ($i + 1);
                                $phenotype_table_field_list[] = $field_list[$i];
                                $num_of_mode_seen = '0';
                                for ($j='0'; $j<$num_of_modes; $j++)
                                  {
                                    if ($mode[$j] != 'Select Type of Search')
                                      {
                                        $num_of_mode_seen = ($num_of_mode_seen + 1);
                                        if ($place_on_field_list == $num_of_mode_seen)
                                          {
                                            $phenotype_table_search_term  = $term[$j];
                                            $phenotype_table_search_mode  = $mode[$j];
                                          }#end if right place on list
                                      }#end if real mode
                                  }#end foreach mode
                              }
			    elseif ((preg_match('/_male_/',$field_list[$i])) or (preg_match('/_female_/',$field_list[$i])))
			      {
				$place_on_field_list = ($i + 1);
                                $phenotype_percent_field_list[] = $field_list[$i];
                                $num_of_mode_seen = '0';
                                for ($j='0'; $j<$num_of_modes; $j++)
                                  {
                                    if ($mode[$j] != 'Select Type of Search')
                                      {
                                        $num_of_mode_seen = ($num_of_mode_seen + 1);
                                        if ($place_on_field_list == $num_of_mode_seen)
                                          {
                                            $phenotype_percent_term_array[] = $term[$j];
                                            $phenotype_percent_mode_array[] = $mode[$j];
                                          }#end if right place on list
                                      }#end if real mode
                                  }#end foreach mode
                              }
                            else
                              {
                                $place_on_field_list = ($i + 1);
                                $final_query_field_list[] = $field_list[$i];
                                $num_of_mode_seen = '0';
                                for ($j='0'; $j<$num_of_modes; $j++)
                                  {
                                    if ($mode[$j] != 'Select Type of Search')
                                      {
                                        $num_of_mode_seen = ($num_of_mode_seen + 1);
                                        if ($place_on_field_list == $num_of_mode_seen)
                                          {
                                            $final_query_term_array[] = $term[$j];
                                            $final_query_mode_array[] = $mode[$j];
                                          }#end if right place on list
                                      }#end if real mode
                                  }#end foreach mode
                              }
                          }#end build search queries

                        if (sizeof($age_group_table_field_list) > '0')
                          {
                            if (sizeof($age_group_table_field_list) > '1')
                              {
                                $age_group_id_array = distinctCompoundTableQuery('age_group_id','age_group_table',$database_id,$age_group_table_field_list,$age_group_table_term_array,$age_group_table_mode_array,$join,'all');
                                if (!is_array($age_group_id_array))
                                  {
				    $date = date('Y-m-d H:i:s');
                                    echo "Error #225: $date<br>\n";
                                    echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
                                    echo "$age_group_id_array<br><br>\n";
                                    echo "Please email the above error using The Comments/Help/Support link on the \n";
		                    echo "left navigation bar.\n";
		                    echo "</form>\n";
		                    echo "</body></html>\n";
		                    $ret_val = disconnect();
		                    exit;
                                  }#end error in call to distinctCompoundTableQuery
                                if (sizeof($age_group_id_array) > '0')
                                  {
                                    $age_group_id_term = join($age_group_id_array,',');
                                    $final_query_field_list[] = 'age_group_id';
                                    $final_query_term_array[] = $age_group_id_term;
                                    $final_query_mode_array[] = 'in';
                                  }
                                else #no records
                                  {
                                    if ($join == 'and')
                                      {
                                        echo "<center>\n";
		                        echo "Your search of the Age Group-Phenotype Percentile Link Table did not yield any individuals.<br>\n";
		                        echo "Please try a new search with different search criteria.<br>\n";
					echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                        echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                        echo "</center>\n";
		                        echo "</form>\n";
		                        echo "</body></html>\n";
		                        $ret_val = disconnect();
		                        exit;
                                      }#end if join == and
                                  }#end else no records
				unset($age_group_id_array);
                              }#end if more than one field
                            else #only one field
                              {
                                $age_group_id_array = distinctTableQuery('age_group_id','age_group_table',$database_id,$age_group_table_field_list,$age_group_table_term_array[0],$age_group_table_mode_array[0],'all');
                                if (!is_array($age_group_id_array))
                                  {
				    $date = date('Y-m-d H:i:s');
                                    echo "Error #226: $date<br>\n";
                                    echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
                                    echo "$age_group_id_array<br><br>\n";
                                    echo "Please email the above error using The Comments/Help/Support link on the \n";
		                    echo "left navigation bar.\n";
		                    echo "</form>\n";
		                    echo "</body></html>\n";
		                    $ret_val = disconnect();
		                    exit;
                                  }#end error in call to distinctTableQuery
                                if (sizeof($age_group_id_array) > '0')
                                  {
                                    $age_group_id_term = join($age_group_id_array,',');
                                    $final_query_field_list[] = 'age_group_id';
                                    $final_query_term_array[] = $age_group_id_term;
                                    $final_query_mode_array[] = 'in';
                                  }
                                else #no records
                                  {
                                    if ($join == 'and')
                                      {
                                        echo "<center>\n";
		                        echo "Your search of the Age Group-Phenotype Percenitle Link Table did not yield any individuals.<br>\n";
		                        echo "Please try a new search with different search criteria.<br>\n";
					echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                        echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                        echo "</center>\n";
		                        echo "</form>\n";
		                        echo "</body></html>\n";
		                        $ret_val = disconnect();
		                        exit;
                                      }#end if join == and
                                  }#end else no records
				unset($age_group_id_array);
                              }#end else only one field
                          }#end if have age_group_table fields

                        if (sizeof($phenotype_table_field_list) > '0')
                          {
                            $phenotype_id_array = distinctTableQuery('phenotype_id','phenotype_table',$database_id,$phenotype_table_field_list,$phenotype_table_search_term,$phenotype_table_search_mode,'all');
                            if (!is_array($phenotype_id_array))
                              {
				$date = date('Y-m-d H:i:s');
                                echo "Error #227: $date<br>\n";
                                echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
                                echo "$phenotype_id_array<br><br>\n";
                                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
                              }#end error in call to distinctTableQuery
                            if (sizeof($phenotype_id_array) > '0')
                              {
                                $phenotype_id_term = join($phenotype_id_array,',');
                                $final_query_field_list[] = 'phenotype_id';
                                $final_query_term_array[] = $phenotype_id_term;
                                $final_query_mode_array[] = 'in';
                              }
                            else #no records
                              {
                                if ($join == 'and')
                                  {
                                    echo "<center>\n";
		                    echo "Your search of the Age Group-Phenotype Link Table did not yield any individuals.<br>\n";
		                    echo "Please try a new search with different search criteria.<br>\n";
				    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                    echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                    echo "</center>\n";
		                    echo "</form>\n";
		                    echo "</body></html>\n";
		                    $ret_val = disconnect();
		                    exit;
                                  }#end if join == and
                              }#end else no records
			    unset($phenotype_id_array);
                          }#end if have phenotype_table field

                        $ag_pheno_rec_list = compoundTableQuery($table_name,$database_id,$final_query_field_list,$final_query_term_array,$final_query_mode_array,$join,'all');
                        if (!is_array($ag_pheno_rec_list))
                          {
			    $date = date('Y-m-d H:i:s');
                            echo "Error #228: $date<br>\n";
                            echo "Error in call to compoundTableQuery from individual_search.php<br>\n";
                            echo "$ag_pheno_rec_list<br><br>\n";
                            echo "Please email the above error using The Comments/Help/Support link on the \n";
		            echo "left navigation bar.\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
                          }#end error in call to compoundTableQuery
                        if (sizeof($ag_pheno_rec_list) == '0')
                          {
                            echo "<center>\n";
		            echo "Your search of the Age Group-Phenotype Percentile Table did not yield any individuals.<br>\n";
		            echo "Please try a new search with different search criteria.<br><br>\n";
			    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		            echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                            echo "</center>\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
                          }#end if no records

                        $field_list_array = array('phenotype_name');
			$age_phenotype_id_array = distinctTableQuery('phenotype_id','phenotype_table',$database_id,$field_list_array,'age','equal','all');
			if (!is_array($age_phenotype_id_array))
			  {
			    $date = date('Y-m-d H:i:s');
                            echo "Error #229: $date<br>\n";
                            echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
                            echo "$age_phenotype_id_array<br><br>\n";
                            echo "Please email the above error using The Comments/Help/Support link on the \n";
		            echo "left navigation bar.\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
                          }#end error in call to distinctTableQuery
			if (sizeof($age_phenotype_id_array) == '0')
			  {
			    echo "<center>\n";
                            echo "Cannot execute your query of the Age Group-Phenotype Percentile Link Table for individuals.<br>\n";
			    echo "The reason for this is that there is no 'age' phenotype defined in the database.<br>\n";
			    echo "Therefore cannot find individuals whose ages fall within the defined Age Groups.<br>\n";
			    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		            echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                            echo "</center>\n";
		            echo "</form>\n";
		            echo "</body></html>\n";
		            $ret_val = disconnect();
		            exit;
                          }#end if no age phenotype
			elseif(sizeof($age_phenotype_id_array) == 1) {$age_phenotype_id = $age_phenotype_id_array[0];}
			else
			  {
			    $date = date('Y-m-d H:i:s');
			    echo "Error #230: $date<br>\n";
			    echo "User wanted to search for individuals based upon age group criteria, but when query the phenotype \n";
			    echo "table for the phenotype id of the 'age' phenotype multiple records were returned.<br><br>\n";
			    echo "Please email the above error using the Comments/Help/Support link on the \n";
			    echo "left navigation bar.\n";
			    echo "</form>\n";
			    echo "</body></html>\n";
			    $ret_val = disconnect();
			    exit;
			  }#end error in data integrity
			unset($age_phenotype_id_array);

			$indiv_table_id_array = array();
			foreach ($ag_pheno_rec_list as $ag_pheno_rec)
			  {
			    $age_group_id = $ag_pheno_rec['age_group_id'];
			    $phenotype_id = $ag_pheno_rec['phenotype_id'];

			    $field_list_array = array('age_group_id');
			    $age_group_rec_list = tableQuery('age_group_table',$database_id,$field_list_array,$age_group_id,'equal','all');
			    if (!is_array($age_group_rec_list))
			      {
				$date = date('Y-m-d H:i:s');
				echo "Error #231: $date<br>\n";
				echo "Error in call to tableQuery from individual_search.php<br>\n";
				echo "$age_group_rec_list<br><br>\n";
				echo "Please email the above error using The Comments/Help/Support link on the \n";
				echo "left navigation bar.\n";
				echo "</form>\n";
				echo "</body></html>\n";
				$ret_val = disconnect();
				exit;
			      }#end error in call to tableQuery
			    if (sizeof($age_group_rec_list) == 1) {$age_group_rec = $age_group_rec_list[0];}
			    else #error in data integrity
			      {
				$date = date('Y-m-d H:i:s');
				echo "Error #232: $date<br>\n";
				echo "Error in call to individual_search.php<br>\n";
				echo "User wanted to search for individuals based upon age group-phenotype percentile criteria.<br>\n";
				echo "Query returned age_group_phenotype_percentile_link_id $ag_pheno_rec[age_group_phenotype_percentile_link_id] \n";
				echo "which has age_group_id $age_group_id, but when query the age_group_table with that id ".sizeof($age_group_rec_list)." \n";
				echo "records were returned.<br><br>\n";
				echo "Please email the above error using the Comments/Help/Support link on the \n";
				echo "left navigation bar.\n";
				echo "</form>\n";
				echo "</body></html>\n";
				$ret_val = disconnect();
				exit;
			      }#end error in data integrity
			    $min_age = $age_group_rec['age_group_min_age'];
			    $max_age = $age_group_rec['age_group_max_age'];
			    $nationality = $age_group_rec['nationality'];
			    unset($age_group_rec,$age_group_rec_list);

			    $query_min_age = $min_age - 1;
			    $query_max_age = $max_age + 1;
			    $query_field_list = array('phenotype_id','phenotype_value','phenotype_value');
			    $query_term_array = array($age_phenotype_id,$query_min_age,$query_max_age);
			    $query_mode_array = array('equal','greater_than','less_than');
				    
			    $field_list_array = array('nationality');
			    $nat_ped_table_id_array = distinctTableQuery('pedigree_table_id','pedigree_table',$database_id,$field_list_array,$nationality,'equal','all');
			    if (!is_array($nat_ped_table_id_array))
			      {
				$date = date('Y-m-d H:i:s');
				echo "Error #233: $date<br>\n";
				echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
				echo "$nat_ped_table_id_array<br><br>\n";
				echo "Please email the above error using The Comments/Help/Support link on the \n";
				echo "left navigation bar.\n";
				echo "</form>\n";
				echo "</body></html>\n";
				$ret_val = disconnect();
				exit;
			      }#end error in call to distinctTableQuery
			    if (sizeof($nat_ped_table_id_array) > '0')
			      {
				$nat_ped_table_id_term = join($nat_ped_table_id_array,',');
				unset($nat_ped_table_id_array);

				if (sizeof($phenotype_percent_field_list) > '0')
                                  {
                                    $male_flag   = 0;
                                    $female_flag = 0;
                                    foreach ($phenotype_percent_field_list as $field)
                                      {
                                        if (preg_match('/_male_/',$field))   {$male_flag = 1;}
                                        if (preg_match('/_female_/',$field)) {$female_flag = 1;}
                                      }
                                    if (($male_flag == 1) and ($female_flag == 1)) 
                                      {
                                        $field_list_array  = array('pedigree_table_id');
                                        $search_term_array = array($nat_ped_table_id_term);
                                        $search_mode_array = array('in');
                                      }
                                    else
                                      {
                                        $field_list_array = array('pedigree_table_id','sex');
                                        if ($male_flag == 1) {$search_term_array = array($nat_ped_table_id_term,'1');}
                                        if ($female_flag == 1) {$search_term_array = array($nat_ped_table_id_term,'2');}
                                        $search_mode_array = array('in','equal');
                                      }
                                  }#end if want to restrict individuals based upon sex and phenotype values
                                else #don't want to restrict individuals based upon sex and phenotype values
			          {
				    $male_flag   = 0;
				    $female_flag = 0;
                                    $field_list_array  = array('pedigree_table_id');
                                    $search_term_array = array($nat_ped_table_id_term);
                                    $search_mode_array = array('in');
                                  }#end else
                                $sex_nat_indiv_table_id_array = distinctCompoundTableQuery('individual_table_id','individual_table',$database_id,$field_list_array,$search_term_array,$search_mode_array,'and','all');
                                if (!is_array($sex_nat_indiv_table_id_array))
				  {
				    $date = date('Y-m-d H:i:s');
				    echo "Error #234: $date<br>\n";
				    echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
				    echo "$sex_nat_indiv_table_id_array<br><br>\n";
				    echo "Please email the above error using The Comments/Help/Support link on the \n";
				    echo "left navigation bar.\n";
				    echo "</form>\n";
				    echo "</body></html>\n";
				    $ret_val = disconnect();
				    exit;
				  }#end error in call to distinctCompoundTableQuery
				if (sizeof($sex_nat_indiv_table_id_array) > '0')
				  {
				    $sex_nat_indiv_table_id_term = join($sex_nat_indiv_table_id_array,',');
				    unset($sex_nat_indiv_table_id_array);

				    if (sizeof($phenotype_percent_field_list) > '0')
				      {
				        if (($male_flag == 1) and ($female_flag == 1))
					  {
					    $field_list_array  = array('individual_table_id','sex');
					    $male_term_array   = array($sex_nat_indiv_table_id_term,'1');
					    $female_term_array = array($sex_nat_indiv_table_id_term,'2');
					    $mode_array        = array('in','equal');

					    $male_indiv_ids_array = distinctCompoundTableQuery('individual_table_id','individual_table',$database_id,$field_list_array,$male_term_array,$mode_array,'and','all');
					    if (!is_array($male_indiv_ids_array))
					      {
						$date = date('Y-m-d H:i:s');
						echo "Error #235: $date<br>\n";
						echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
						echo "$male_indiv_ids_array<br><br>\n";
						echo "Please email the above error using The Comments/Help/Support link on the \n";
						echo "left navigation bar.\n";
						echo "</form>\n";
						echo "</body></html>\n";
						$ret_val = disconnect();
						exit;
					      }#end error in call to distinctCompoundTableQuery
					    $male_indiv_ids_term = term($male_indiv_ids_array,',');
					    unset($male_indiv_ids_array);

                                            $male_query_field_list = $query_field_list;
                                            $male_query_term_array = $query_term_array;
                                            $male_query_mode_array = $query_mode_array;
                                            $male_query_field_list[] = 'individual_table_id';
				            $male_query_term_array[] = $male_indiv_ids_term;
				            $male_query_mode_array[] = 'in';

				            $age_indiv_table_id_array = distinctCompoundTableQuery('individual_table_id','quantitative_phenotype_value_table',$database_id,$male_query_field_list,$male_query_term_array,$male_query_mode_array,'and','all');
				            if (!is_array($age_indiv_table_id_array))
					      {
						$date = date('Y-m-d H:i:s');
						echo "Error #236: $date<br>\n";
						echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
						echo "$age_indiv_table_id_array<br><br>\n";
						echo "Please email the above error using The Comments/Help/Support link on the \n";
						echo "left navigation bar.\n";
						echo "</form>\n";
						echo "</body></html>\n";
						$ret_val = disconnect();
						exit;
					      }#end error in call to distinctCompoundTableQuery
				            $age_indiv_table_id_term = join($age_indiv_table_id_array,',');
					    unset($age_indiv_table_id_array);

					    $male_query_field_list = array('individual_table_id','phenotype_id');
					    $male_query_term_array = array($age_indiv_table_id_term,$phenotype_id);
					    $male_query_mode_array = array('in','equal');
					    for ($i =0; $i <= sizeof($phenotype_percent_field_list); $i++)
                                              {
                                                if (preg_match('/_male_/',$phenotype_percent_field_list[$i]))
                                                  {
						    $male_query_field_list[] = 'phenotype_value';
						    $male_query_term_array[] = $ag_pheno_rec[$phenotype_percent_term_array[$i]];
						    $male_query_mode_array[] = $phenotype_percent_mode_array[$i];
                                                  }
                                              }
					    $indiv_ids = distinctCompoundTableQuery('individual_table_id','qualitative_phenotype_value_table',$databse_id,$male_query_field_list,$male_query_term_array,$male_query_mode_array,'and','all');
					    if (!is_array($indiv_ids))
					      {
						$date = date('Y-m-d H:i:s');
						echo "Error #237: $date<br>\n";
						echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
						echo "$indiv_ids<br><br>\n";
						echo "Please email the above error using The Comments/Help/Support link on the \n";
						echo "left navigation bar.\n";
						echo "</form>\n";
						echo "</body></html>\n";
						$ret_val = disconnect();
						exit;
					      }#end error in call to distinctCompoundTableQuery
					    if (sizeof($indiv_ids) > '0')
					      {
						$term = join($indiv_ids,',');
						$indiv_table_id_array[] = $term;
					      }
                                            $indiv_ids = distinctCompoundTableQuery('individual_table_id','quantitative_phenotype_value_table',$databse_id,$male_query_field_list,$male_query_term_array,$male_query_mode_array,'and','all');
					    if (!is_array($indiv_ids))
					      {
						$date = date('Y-m-d H:i:s');
						echo "Error #238: $date<br>\n";
						echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
						echo "$indiv_ids<br><br>\n";
						echo "Please email the above error using The Comments/Help/Support link on the \n";
						echo "left navigation bar.\n";
						echo "</form>\n";
						echo "</body></html>\n";
						$ret_val = disconnect();
						exit;
					      }#end error in call to distinctCompoundTableQuery
					    if (sizeof($indiv_ids) > '0')
					      {
						$term = join($indiv_ids,',');
						$indiv_table_id_array[] = $term;
					      }

					    $female_indiv_ids_array = distinctCompoundTableQuery('individual_table_id','individual_table',$database_id,$field_list_array,$female_term_array,$mode_array,'and','all');
					    if (!is_array($female_indiv_ids_array))
					      {
						$date = date('Y-m-d H:i:s');
						echo "Error #239: $date<br>\n";
						echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
						echo "$female_indiv_ids_array<br><br>\n";
						echo "Please email the above error using The Comments/Help/Support link on the \n";
						echo "left navigation bar.\n";
						echo "</form>\n";
						echo "</body></html>\n";
						$ret_val = disconnect();
						exit;
					      }#end error in call to distinctCompoundTableQuery
					    $female_indiv_ids_term = join($female_indiv_ids_array,',');
					    unset($female_indiv_ids_array);

                                            $female_query_field_list = $query_field_list;
                                            $female_query_term_array = $query_term_array;
                                            $female_query_mode_array = $query_mode_array;
                                            $female_query_field_list[] = 'individual_table_id';
				            $female_query_term_array[] = $female_indiv_ids_term;
				            $female_query_mode_array[] = 'in';

				            $age_indiv_table_id_array = distinctCompoundTableQuery('individual_table_id','quantitative_phenotype_value_table',$database_id,$female_query_field_list,$female_query_term_array,$female_query_mode_array,'and','all');
				            if (!is_array($age_indiv_table_id_array))
					      {
						$date = date('Y-m-d H:i:s');
						echo "Error #240: $date<br>\n";
						echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
						echo "$age_indiv_table_id_array<br><br>\n";
						echo "Please email the above error using The Comments/Help/Support link on the \n";
						echo "left navigation bar.\n";
						echo "</form>\n";
						echo "</body></html>\n";
						$ret_val = disconnect();
						exit;
					      }#end error in call to distinctCompoundTableQuery
				            $age_indiv_table_id_term = join($age_indiv_table_id_array,',');
					    unset($age_indiv_table_id_array);

					    $female_query_field_list = array('individual_table_id','phenotype_id');
					    $female_query_term_array = array($age_indiv_table_id_term,$phenotype_id);
					    $female_query_mode_array = array('in','equal');
					    for ($i =0; $i <= sizeof($phenotype_percent_field_list); $i++)
                                              {
                                                if (preg_match('/_female_/',$phenotype_percent_field_list[$i]))
                                                  {
						    $female_query_field_list[] = 'phenotype_value';
						    $female_query_term_array[] = $ag_pheno_rec[$phenotype_percent_term_array[$i]];
						    $female_query_mode_array[] = $phenotype_percent_mode_array[$i];
                                                  }
                                              }
					    $indiv_ids = distinctCompoundTableQuery('individual_table_id','qualitative_phenotype_value_table',$databse_id,$female_query_field_list,$female_query_term_array,$female_query_mode_array,'and','all');
					    if (!is_array($indiv_ids))
					      {
						$date = date('Y-m-d H:i:s');
						echo "Error #241: $date<br>\n";
						echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
						echo "$indiv_ids<br><br>\n";
						echo "Please email the above error using The Comments/Help/Support link on the \n";
						echo "left navigation bar.\n";
						echo "</form>\n";
						echo "</body></html>\n";
						$ret_val = disconnect();
						exit;
					      }#end error in call to distinctCompoundTableQuery
					    if (sizeof($indiv_ids) > '0')
					      {
						$term = join($indiv_ids,',');
						$indiv_table_id_array[] = $term;
					      }
                                            $indiv_ids = distinctCompoundTableQuery('individual_table_id','quantitative_phenotype_value_table',$databse_id,$female_query_field_list,$female_query_term_array,$female_query_mode_array,'and','all');
					    if (!is_array($indiv_ids))
					      {
						$date = date('Y-m-d H:i:s');
						echo "Error #242: $date<br>\n";
						echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
						echo "$indiv_ids<br><br>\n";
						echo "Please email the above error using The Comments/Help/Support link on the \n";
						echo "left navigation bar.\n";
						echo "</form>\n";
						echo "</body></html>\n";
						$ret_val = disconnect();
						exit;
					      }#end error in call to distinctCompoundTableQuery
					    if (sizeof($indiv_ids) > '0')
					      {
						$term = join($indiv_ids,',');
						$indiv_table_id_array[] = $term;
					      }
					    unset($male_query_field_list,$male_query_term_array,$male_query_mode_array);
					    unset($female_query_field_list,$female_query_term_array,$female_query_mode_array);
					  }#end if need to test both male and female phenotype values
				        else #only testing one sex phenotype values
				          {
				            $query_field_list[] = 'individual_table_id';
				            $query_term_array[] = $sex_nat_indiv_table_id_term;
				            $query_mode_array[] = 'in';

				            $age_indiv_table_id_array = distinctCompoundTableQuery('individual_table_id','quantitative_phenotype_value_table',$database_id,$query_field_list,$query_term_array,$query_mode_array,'and','all');
				            if (!is_array($age_indiv_table_id_array))
					      {
						$date = date('Y-m-d H:i:s');
						echo "Error #243: $date<br>\n";
						echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
						echo "$age_indiv_table_id_array<br><br>\n";
						echo "Please email the above error using The Comments/Help/Support link on the \n";
						echo "left navigation bar.\n";
						echo "</form>\n";
						echo "</body></html>\n";
						$ret_val = disconnect();
						exit;
					      }#end error in call to distinctCompoundTableQuery
				            $age_indiv_table_id_term = join($age_indiv_table_id_array,',');
					    unset($age_indiv_table_id_array);

					    $query_field_list = array('individual_table_id','phenotype_id');
					    $query_term_array = array($age_indiv_table_id_term,$phenotype_id);
					    $query_mode_array = array('in','equal');
					    for ($i =0; $i <= sizeof($phenotype_percent_field_list); $i++)
                                              {
						$query_field_list[] = 'phenotype_value';
						$query_term_array[] = $ag_pheno_rec[$phenotype_percent_term_array[$i]];
						$query_mode_array[] = $phenotype_percent_mode_array[$i];
                                              }
					    $indiv_ids = distinctCompoundTableQuery('individual_table_id','qualitative_phenotype_value_table',$databse_id,$query_field_list,$query_term_array,$query_mode_array,'and','all');
					    if (!is_array($indiv_ids))
					      {
						$date = date('Y-m-d H:i:s');
						echo "Error #244: $date<br>\n";
						echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
						echo "$indiv_ids<br><br>\n";
						echo "Please email the above error using The Comments/Help/Support link on the \n";
						echo "left navigation bar.\n";
						echo "</form>\n";
						echo "</body></html>\n";
						$ret_val = disconnect();
						exit;
					      }#end error in call to distinctCompoundTableQuery
					    if (sizeof($indiv_ids) > '0')
					      {
						$term = join($indiv_ids,',');
						$indiv_table_id_array[] = $term;
					      }
                                            $indiv_ids = distinctCompoundTableQuery('individual_table_id','quantitative_phenotype_value_table',$databse_id,$query_field_list,$query_term_array,$query_mode_array,'and','all');
					    if (!is_array($indiv_ids))
					      {
						$date = date('Y-m-d H:i:s');
						echo "Error #245: $date<br>\n";
						echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
						echo "$indiv_ids<br><br>\n";
						echo "Please email the above error using The Comments/Help/Support link on the \n";
						echo "left navigation bar.\n";
						echo "</form>\n";
						echo "</body></html>\n";
						$ret_val = disconnect();
						exit;
					      }#end error in call to distinctCompoundTableQuery
					    if (sizeof($indiv_ids) > '0')
					      {
						$term = join($indiv_ids,',');
						$indiv_table_id_array[] = $term;
					      }
					  }#end else one sex phenotype restricted
				      }#end if sex and phenotype value restricted
				    else #not sex and phenotype value restricted
				      {
                                        $query_field_list[] = 'individual_table_id';
				        $query_term_array[] = $sex_nat_indiv_table_id_term;
				        $query_mode_array[] = 'in';

				        $age_indiv_table_id_array = distinctCompoundTableQuery('individual_table_id','quantitative_phenotype_value_table',$database_id,$query_field_list,$query_term_array,$query_mode_array,'and','all');
				        if (!is_array($age_indiv_table_id_array))
					  {
					    $date = date('Y-m-d H:i:s');
					    echo "Error #246: $date<br>\n";
					    echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
					    echo "$age_indiv_table_id_array<br><br>\n";
					    echo "Please email the above error using The Comments/Help/Support link on the \n";
					    echo "left navigation bar.\n";
					    echo "</form>\n";
					    echo "</body></html>\n";
					    $ret_val = disconnect();
					    exit;
					  }#end error in call to distinctCompoundTableQuery
				        $age_indiv_table_id_term = join($age_indiv_table_id_array,',');
					unset($age_indiv_table_id_array);

					$query_field_list = array('individual_table_id','phenotype_id');
					$query_term_array = array($age_indiv_table_id_term,$phenotype_id);
					$query_mode_array = array('in','equal');
                                        $indiv_ids = distinctCompoundTableQuery('individual_table_id','qualitative_phenotype_value_table',$databse_id,$query_field_list,$query_term_array,$query_mode_array,'and','all');
					if (!is_array($indiv_ids))
					  {
					    $date = date('Y-m-d H:i:s');
					    echo "Error #247: $date<br>\n";
					    echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
					    echo "$indiv_ids<br><br>\n";
					    echo "Please email the above error using The Comments/Help/Support link on the \n";
					    echo "left navigation bar.\n";
					    echo "</form>\n";
					    echo "</body></html>\n";
					    $ret_val = disconnect();
					    exit;
					  }#end error in call to distinctCompoundTableQuery
					if (sizeof($indiv_ids) > '0')
					  {
					    $term = join($indiv_ids,',');
					    $indiv_table_id_array[] = $term;
					  }

                                        $indiv_ids = distinctCompoundTableQuery('individual_table_id','quantitative_phenotype_value_table',$databse_id,$query_field_list,$query_term_array,$query_mode_array,'and','all');
					if (!is_array($indiv_ids))
					  {
					    $date = date('Y-m-d H:i:s');
					    echo "Error #248: $date<br>\n";
					    echo "Error in call to distinctCompoundTableQuery from individual_search.php<br>\n";
					    echo "$indiv_ids<br><br>\n";
					    echo "Please email the above error using The Comments/Help/Support link on the \n";
					    echo "left navigation bar.\n";
					    echo "</form>\n";
					    echo "</body></html>\n";
					    $ret_val = disconnect();
					    exit;
					  }#end error in call to distinctCompoundTableQuery
					if (sizeof($indiv_ids) > '0')
					  {
					    $term = join($indiv_ids,',');
					    $indiv_table_id_array[] = $term;
					  }
				      }#end else not sex and phenotype value restricted
				  }#end if individuals who meet sex and nationality requirements
			      }#end if have pedigrees who meet nationality requirement
			    unset($query_field_list,$query_term_array,$query_mode_array);
			  }#end foreach ag_pheno_rec_list
			unset($ag_pheno_rec,$ag_pheno_rec_list);

			if (sizeof($indiv_table_id_array) == '0')
			  {
			    echo "<center>\n";
			    echo "Your search of the Age Group-Phenotype Percentile Link Table did not yield any individuals.<br>\n";
			    echo "Please try a new search with different search criteria.<br><br>\n";
			    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
			    echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
			    echo "</center>\n";
			    echo "</form>\n";
			    echo "</body></html>\n";
			    $ret_val = disconnect();
			    exit;
			  }#end if sizeof(rec_list) == '0'
                        $indiv_table_id_term = join($indiv_table_id_array,',');
			unset($indiv_table_id_array);

                        $field_list_array = array('individual_table_id');
			$num_of_indivs = countTableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in');
			if (!preg_match('/^\d+$/',$num_of_indivs))
                          {
                            $date = date('Y-m-d H:i:s');
                            echo "Error #249: $date<br>\n";
			    echo "Error in call to countTableQuery from individual_search.php<br>\n";
			    echo "$num_of_indivs<br><br>\n";
			    echo "Please email the above error using the Comments/Help/Support link on the \n";
			    echo "left navigation bar.\n";
			    echo "</form>\n";
			    echo "</body></html>\n";
			    $ret_val = disconnect();
			    exit;
		          }#end error in call to countTableQuery

                        #if ($num_of_indivs > $max_records_to_print)
                        #  {
                        #    echo "Your search returned $num_of_indivs individuals.<br>\n";
                        #    tooManyIndividuals($indiv_table_id_term);
                        #    $ret_val = disconnect();
                        #    exit;
                        #  }#end if more than max to print

		        if ($num_of_indivs > ($max_records_to_print_per_page * 5))
                          {
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                            $indiv_table_id_array = distinctTableQuery('individual_table_id','individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in','all',$order_by);
                            if (!is_array($indiv_table_id_array))
                              {
                                $date = date('Y-m-d H:i:s');
			        echo "Error #250: $date<br>\n";
			        echo "Error in call to distincTableQuery from individual_search.php<br>\n";
			        echo "$indiv_table_id_array<br><br>\n";
			        echo "Please email the above error using the Comments/Help/Support link on the \n";
			        echo "left navigation bar.\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if error call to distinctTableQuery
                            $all_indiv_table_id_term = join($indiv_table_id_array,',');
                            unset($indiv_table_id_array);

                            moreThanFivePages($all_indiv_table_id_term);
                            unset($all_indiv_table_id_term);
                          }#end if more than 5 pages returned

		        if ($num_of_indivs > $max_records_to_print_per_page)
		          {
			    $indiv_multiple_pages = 1;
                            $from                 = "0";
                            $to                   = $max_records_to_print_per_page - 1;
                            $range                = "$from"."-"."$to";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
			    $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in',$range,$order_by);
			    if (!is_array($indiv_rec_list))
			      {
			        $date = date('Y-m-d H:i:s');
			        echo "Error #251: $date<br>\n";
			        echo "Error in call to tableQuery from individual_search.php<br>\n";
			        echo "$indiv_rec_list<br><br>\n";
			        echo "Please email the above error using the Comments/Help/Support link on the \n";
			        echo "left navigation bar.\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if (!is_array(indiv_rec_list))
                            if (sizeof($indiv_rec_list) == '0')
			      {
			        echo "<center>\n";
			        echo "Your search of the Age Group-Phenotype Percentile Link Table did not yield any individuals.<br>\n";
			        echo "Please try your search again with different search criteria.<br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
			        echo "<input type=\"submit\" name=\"submit\" value=\"Start New Search\">\n";
			        echo "</center>\n";
			        echo "</form>\n";
			        echo "</body></html>\n";
			        $ret_val = disconnect();
			        exit;
			      }#end if (sizeof(indiv_rec_list) == '0')
			    $final_function_call   = 'tableQuery';
			    $final_table_name      = 'individual_table';
			    $final_field_list      = $field_list_array;
			    $final_term            = $indiv_table_id_term;
			    $final_mode            = 'in';
			    $final_order_by        = $order_by;
                            $last_record_retrieved = $max_records_to_print_per_page;
                          }#end if more than a single page
                        else #only a single page
		          {
			    $indiv_multiple_pages = 0;
                            $range                = "all";
                            if ($db_type == 'mysql'){$order_by = 'pedigree_id+0,individual_id+0';}
                            if ($db_type == 'pgsql'){$order_by = "pedigree_id::text::integer,individual_id::text::integer";}
                            $indiv_rec_list = tableQuery('individual_table',$database_id,$field_list_array,$indiv_table_id_term,'in',$range,$order_by);
		            if (!is_array($indiv_rec_list))
                              {
			        $date = date('Y-m-d H:i:s');
		                echo "Error #252: $date<br>\n";
		                echo "Error in call to tableQuery from individual_search.php<br>\n";
		                echo "$indiv_rec_list<br><br>\n";
		                echo "Please email the above error using The Comments/Help/Support link on the \n";
		                echo "left navigation bar.\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (!is_array(indiv_rec_list))
		            if (sizeof($indiv_rec_list) == '0')
                              {
                                echo "<center>\n";
		                echo "Your search of the Age Group-Phenotype Percentile Link Table did not yield any individuals.<br>\n";
		                echo "Please try a new search with different search criteria.<br><br>\n";
			        echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		                echo "<input type=\"submit\" name=\"submit\" value=\"Start a New Search\">\n";
                                echo "</center>\n";
		                echo "</form>\n";
		                echo "</body></html>\n";
		                $ret_val = disconnect();
		                exit;
		              }#end if (sizeof(indiv_rec_list) == '0')
			  }#end else only a single page
                      }#end else sizeof(field_list) > '1'
                   }#end if table_name == age_group_phenotype_percentile_link_table

		 else
                   {
		    echo "The table $table_name is not a searchable table in the database.<br>\n";
		    echo "Please try a new search with correct search criteria.<br>\n";
		    echo "<form action=\"individual_search.php\" method=\"POST\" target=\"main\">\n";
		    echo "<center><input type=\"submit\" name=\"submit\" value=\"Start a New Search\"></center>\n";
		    echo "</form>\n";
		    echo "</body></html>\n";
		    $ret_val = disconnect();
		    exit;
		   }#end else not a good table_name

		 echo "Your search of the $table_aliases[$table_name] table returned $num_of_indivs individual records.<br>\n";
                 if ($indiv_multiple_pages) {echo "Here are the first $max_records_to_print_per_page of those records<br><br>\n";}
                 else                       {echo "Here are all $num_of_indivs records<br><br>\n";}

		 $ret_val = printLogOutButton('individual_search.php');
                 echo "<br><br>\n";

                 if ($indiv_multiple_pages) 
		   {
                     echo "<table align=\"center\">\n";
                     echo "<form action=\"download.php\" name=\"download_form1\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";
                     echo "<input type=\"hidden\" name=\"type_of_download\" value=\"individual_record\">\n";
                     echo "<input type=\"hidden\" name=\"indiv_id\" value=\"\">\n";
                     echo "<tr>\n";
                     echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Selected Individual's Information\" onClick=\"copyData('download_form1')\"></td>\n";
                     echo "</form>\n";

                     echo "<form action=\"individual_search.php\" name=\"skip_form1\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";
                     echo "<input type=\"hidden\" name=\"individual_flag\" value=\"1\">\n";
                     echo "<input type=\"hidden\" name=\"indiv_multiple_pages\" value=\"0\">\n";
                     echo "<input type=\"hidden\" name=\"indiv_id\" value=\"\">\n";
                     echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes for Selected Individuals\" onClick=\"copyData('skip_form1')\"></td>\n";
                     echo "</form>\n";
                     echo "</tr>\n";

                     echo "<form action=\"individual_search.php\" name=\"form\" method=\"POST\" target=\"main\">\n";
		     $records_left = ($num_of_indivs - $last_record_retrieved);
                     echo "<tr>\n";
                     if ($records_left > $max_records_to_print_per_page)
                       {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Next $max_records_to_print_per_page Individuals\"></td>\n";}
                     else
		       {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Next $records_left Individuals\"></td>\n";}
                     echo "<td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Deselect Selections\"></td>\n";
                     echo "</tr>\n";
                     echo "</table>\n";
		   }#end multiple pages
		 else #only one page
		   {
                     echo "<table align=\"center\">\n";
                     echo "<form action=\"download.php\" name=\"download_form1\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";
                     echo "<input type=\"hidden\" name=\"type_of_download\" value=\"individual_record\">\n";
                     echo "<input type=\"hidden\" name=\"indiv_id\" value=\"\">\n";
                     echo "<tr>\n";
                     echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Selected Individual's Information\" onClick=\"copyData('download_form1')\"></td>\n";
                     echo "</form>\n";

                     echo "<form action=\"individual_search.php\" name=\"form\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(this))\">\n";
		     echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes for Selected Individuals\"></td>\n";
                     echo "</tr>\n";
                     echo "</table>\n";
                     echo "<br>\n";
                     echo "<table align=\"center\">\n";
                     echo "<tr>\n";
                     echo "<td align=\"center\">&nbsp;</td>\n";
                     echo "<td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Deselect Selections\"></td>\n";
                     echo "</tr>\n";
                     echo "</table>\n";
		   }
		 echo "<br><br>\n";

                 $jscript = printIndividualCheckList($indiv_rec_list,$database_id);
		 if ($jscript == '0')
                   {
                     $date = date('Y-m-d H:i:s');
		     echo "Error #253: $date<br>\n";
		     echo "Error in call to printIndividualCheckList from individual_search.php<br>\n";
		     echo "See above error message from printIndividualCheckList for an explanation<br><br>\n";
		     echo "Please email the above error using the Comments/Help/Support link on the \n";
		     echo "left navigation bar.\n";
		     echo "</form>\n";
		     echo "</body></html>\n";
		     $ret_val = disconnect();
		     exit;
		   }#end if (jscript == '0')
		 echo "<br><br>\n";

                 echo "<input type=\"hidden\" name=\"individual_flag\" value=\"1\">\n";
                 echo "<input type=\"hidden\" name=\"indiv_multiple_pages\" value=\"$indiv_multiple_pages\">\n";
                 if ($indiv_multiple_pages)
                   {
                     echo "<input type=\"hidden\" name=\"function_to_call\" value=\"$final_function_call\">\n";

                     if ($final_function_call == 'tableJoin') 
                       {
                         foreach ($final_table_name as $name) {echo "<input type=\"hidden\" name=\"table_name[]\" value=\"$name\">\n";}
                       }
                     else{echo "<input type=\"hidden\" name=\"table_name\" value=\"$final_table_name\">\n";}

		     foreach ($final_field_list as $field){echo "<input type=\"hidden\" name=\"field_list[]\" value=\"$field\">\n";}

                     if (is_array($final_term)){foreach ($final_term as $term){echo "<input type=\"hidden\" name=\"term[]\" value=\"$term\">\n";}}
                     else {echo "<input type=\"hidden\" name=\"term\" value=\"$final_term\">\n";}

                     if (is_array($final_mode)){foreach ($final_mode as $mode){echo "<input type=\"hidden\" name=\"mode[]\" value=\"$mode\">\n";}}
                     else {echo "<input type=\"hidden\" name=\"mode\" value=\"$final_mode\">\n";}

                     if ($final_function_call == 'compoundTableQuery') {echo "<input type=\"hidden\" value=\"join\" value=\"$final_join\">\n";}

                     echo "<input type=\"hidden\" name=\"order_by\" value=\"$final_order_by\">\n";
                     echo "<input type=\"hidden\" name=\"last_record_retrieved\" value=\"$last_record_retrieved\">\n";

                     echo "<table align=\"center\">\n";
                     echo "<tr>\n";
                     echo "<td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Reset Selections\"></td>\n";
                     if ($records_left > $max_records_to_print_per_page)
                       {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get next $max_records_to_print_per_page Individual Records\"></td>\n";}
		     else
                       {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get next $records_left Individual Records\"></td>\n";}
                     echo "</form>\n";
                     echo "</tr>\n";

                     echo "<form action=\"download.php\" name=\"download_form2\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";
                     echo "<input type=\"hidden\" name=\"type_of_download\" value=\"individual_record\">\n";
                     echo "<input type=\"hidden\" name=\"indiv_id\" value=\"\">\n";
                     echo "<tr>\n";
                     echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Selected Individual's Information\" onClick=\"copyData('download_form2')\"></td>\n";
                     echo "</form>\n";

                     echo "<form action=\"individual_search.php\" name=\"skip_form2\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";
                     echo "<input type=\"hidden\" name=\"individual_flag\" value=\"1\">\n";
                     echo "<input type=\"hidden\" name=\"indiv_multiple_pages\" value=\"0\">\n";
                     echo "<input type=\"hidden\" name=\"indiv_id\" value=\"\">\n";
                     echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes for Selected Individuals\" onClick=\"copyData('skip_form2')\"></td>\n";
                     echo "</form>\n";
                     echo "</tr>\n";
                     echo "</table>\n";
		   }#end if have multiple pages of results to display
		 else #only one page of results
		   {
                     echo "<table align=\"center\">\n";
                     echo "<tr>\n";
                     echo "<td align=\"center\>&nbsp;</td>\n";
                     echo "<td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Reset Selections\"></td>\n";
                     echo "</tr>\n";
                     echo "</table>\n";
                     echo "<br>\n";
                     echo "<table align=\"center\">\n";
                     echo "<tr>\n";
                     echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes for Selected Individuals\"></td>\n";
                     echo "</form>\n";

                     echo "<form action=\"download.php\" name=\"download_form2\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";
                     echo "<input type=\"hidden\" name=\"type_of_download\" value=\"individual_record\">\n";
                     echo "<input type=\"hidden\" name=\"indiv_id\" value=\"\">\n";
                     echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Selected Individual's Information\" onClick=\"copyData('download_form2')\"></td>\n";
                     echo "</form>\n";
                     echo "</tr>\n";
                     echo "</table>\n";
		   }#end else only one page of results
                 echo "<br><br>\n\n";

                 $ret_val = printLogOutButton('individual_search.php');
		 echo "\n\n";
		    
		 echo "<script>\n";
		 echo "function Validate(form)\n";
                 echo "$jscript\n";
                 echo "\n";
                 echo "function copyData(form_to_copy_to)\n";
                 echo "{\n";
                 echo " var indiv_string = new Array();\n";
                 echo " var length = 0;\n";
                 echo " for (var i=0; i<document.form.elements['indiv_id[]'].length; i++){\n";
                 echo "   if (document.form.elements['indiv_id[]'][i].checked){\n";
                 echo "     length = indiv_string.length;\n";
                 echo "     indiv_string[length] = document.form.elements['indiv_id[]'][i].value;}}\n";
                 echo " if (form_to_copy_to == \"skip_form1\"){\n";
                 echo "   document.skip_form1.indiv_id.value = indiv_string;}\n";
                 echo " if (form_to_copy_to == \"skip_form2\"){\n";
                 echo "   document.skip_form2.indiv_id.value = indiv_string;}\n";
                 echo " if (form_to_copy_to == \"download_form1\"){\n";
                 echo "   document.download_form1.indiv_id.value = indiv_string;}\n";
                 echo " if (form_to_copy_to == \"download_form2\"){\n";
                 echo "   document.download_form2.indiv_id.value = indiv_string;}\n";
                 echo "}\n";
		 echo "</script>\n";
                 unset($indiv_multiple_pages);
	        }#end if have table_name,field_list,term, and mode
	     }#end if individual_flag != '1'

           #6    Need multiple pages to display all the individuals returned from query
	   if (($individual_flag == '1') and ($indiv_multiple_pages == '1'))#the number of individuals returned too large to display on a single page
	     {
	       echo "Select which Individuals you want data for:<br><br>\n";

	       if ($function_to_call == 'tableQuery')
		 {
		   $num_of_indivs = countTableQuery($table_name,$database_id,$field_list,$term,$mode);
		   if (!preg_match('/^\d+$/',$num_of_indivs))
		     {
		       $date = date('Y-m-d H:i:s');
		       echo "Error #254: $date<br>\n";
		       echo "Error in call to countTableQuery from individual_search.php<br>\n";
		       echo "$num_of_indivs<br><br>\n";
		       echo "Please email the above error using The Comments/Help/Support link on the \n";
		       echo "left navigation bar.\n";
		       echo "</form>\n";
		       echo "</body></html>\n";
		       $ret_val = disconnect();
		       exit;
		     }#end error in call to countTableQuery
		   $records_yet_to_be_retrieved = $num_of_indivs - $last_record_retrieved;

                   if ($records_yet_to_be_retrieved > $max_records_to_print_per_page)
                     {
                       $indiv_multiple_pages = 1;
                       $from                 = $last_record_retrieved;
                       $to                   = ($last_record_retrieved-1) + $max_records_to_print_per_page;
                       $range                = "$from"."-"."$to";
                       $indiv_rec_list = tableQuery($table_name,$database_id,$field_list,$term,$mode,$range,$order_by);
                       if (!is_array($indiv_rec_list))
		         {
		           $date = date('Y-m-d H:i:s');
		           echo "Error #255: $date<br>\n";
		           echo "Error in call to tableQuery from individual_search.php<br>\n";
		           echo "$indiv_rec_list<br><br>\n";
		           echo "Please email the above error using The Comments/Help/Support link on the \n";
		           echo "left navigation bar.\n";
		           echo "</form>\n";
		           echo "</body></html>\n";
		           $ret_val = disconnect();
		           exit;
		         }#end if (!is_array(indiv_rec_list))
		       if (sizeof($indiv_rec_list) == 0)
			 {
			   $date = date('Y-m-d H:i:s');
                           echo "Error #256: $date<br>\n";
		           echo "Error in call to individual_search.php<br>\n";
		           echo "There should be records returned for tableQuery search with parameters:<br>\n";
                           echo "table_name = $table_name<br>\n";
                           echo "field_list = ".join(',',$field_list)."<br>\n";
                           echo "term       = $term<br>\n";
                           echo "mode       = $mode<br>\n";
                           echo "range      = $range<br>\n";
                           echo "order_by   = $order_by<br>\n";
                           echo "But no records were returned<br><br>\n";
		           echo "Please email the above error using The Comments/Help/Support link on the \n";
		           echo "left navigation bar.\n";
		           echo "</form>\n";
		           echo "</body></html>\n";
		           $ret_val = disconnect();
		           exit;
		         }#end if no records returned
                       $last_record_retrieved = $to + 1;
		     }#end if more than a single page
		   else #only a single page
		     {
                       $indiv_multiple_pages = 0;
		       $from                 = $last_record_retrieved;
                       $to                   = $num_of_indivs - 1;
                       $range                = "$from"."-"."$to";
		       $indiv_rec_list = tableQuery($table_name,$database_id,$field_list,$term,$mode,$range,$order_by);
                       if (!is_array($indiv_rec_list))
		         {
		           $date = date('Y-m-d H:i:s');
		           echo "Error #257: $date<br>\n";
		           echo "Error in call to tableQuery from individual_search.php<br>\n";
		           echo "$indiv_rec_list<br><br>\n";
		           echo "Please email the above error using The Comments/Help/Support link on the \n";
		           echo "left navigation bar.\n";
		           echo "</form>\n";
		           echo "</body></html>\n";
		           $ret_val = disconnect();
		           exit;
		         }#end if (!is_array(indiv_rec_list))
                       if (sizeof($indiv_rec_list) == 0)
			 {
			   $date = date('Y-m-d H:i:s');
                           echo "Error #258: $date<br>\n";
		           echo "Error in call to individual_search.php<br>\n";
		           echo "There should be records returned for tableQuery search with parameters:<br>\n";
                           echo "table_name = $table_name<br>\n";
                           echo "field_list = ".join(',',$field_list)."<br>\n";
                           echo "term       = $term<br>\n";
                           echo "mode       = $mode<br>\n";
                           echo "range      = $range<br>\n";
                           echo "order_by   = $order_by<br>\n";
                           echo "But no records were returned<br><br>\n";
		           echo "Please email the above error using The Comments/Help/Support link on the \n";
		           echo "left navigation bar.\n";
		           echo "</form>\n";
		           echo "</body></html>\n";
		           $ret_val = disconnect();
		           exit;
		         }#end if no records returned
		     }#end else only a single page
		 }#end if tableQuery
	       if ($function_to_call == 'tableJoin')
		 {
		   $num_of_indivs = countTableJoin($table_name[0],$table_name[1],$database_id,$field_list,$term,$mode);
		   if (!preg_match('/^\d+$/',$num_of_indivs))
		     {
		       $date = date('Y-m-d H:i:s');
		       echo "Error #259: $date<br>\n";
		       echo "Error in call to countTableJoin from individual_search.php<br>\n";
		       echo "$num_of_indivs<br><br>\n";
		       echo "Please email the above error using The Comments/Help/Support link on the \n";
		       echo "left navigation bar.\n";
		       echo "</form>\n";
		       echo "</body></html>\n";
		       $ret_val = disconnect();
		       exit;
		     }#end error in call to countTableJoin
                   $records_yet_to_be_retrieved = $num_of_indivs - $last_record_retrieved;

                   if ($records_yet_to_be_retrieved > $max_records_to_print_per_page)
                     {
                       $indiv_multiple_pages = 1;
                       $from                 = $last_record_retrieved;
                       $to                   = ($last_record_retrieved - 1) + $max_records_to_print_per_page;
                       $range                = "$from"."-"."$to";
                       $indiv_rec_list = tableJoin($table_name[0],$table_name[1],$database_id,$field_list,$term,$mode,$range,$order_by);
                       if (!is_array($indiv_rec_list))
		         {
		           $date = date('Y-m-d H:i:s');
		           echo "Error #260: $date<br>\n";
		           echo "Error in call to tableJoin from individual_search.php<br>\n";
		           echo "$indiv_rec_list<br><br>\n";
		           echo "Please email the above error using The Comments/Help/Support link on the \n";
		           echo "left navigation bar.\n";
		           echo "</form>\n";
		           echo "</body></html>\n";
		           $ret_val = disconnect();
		           exit;
		         }#end if (!is_array(indiv_rec_list))
                       if (sizeof($indiv_rec_list) == 0)
			 {
			   $date = date('Y-m-d H:i:s');
                           echo "Error #261: $date<br>\n";
		           echo "Error in call to individual_search.php<br>\n";
		           echo "There should be records returned for tableJoin search with parameters:<br>\n";
                           echo "table_name = ".join(',',$table_name)."<br>\n";
                           echo "field_list = ".join(',',$field_list)."<br>\n";
                           echo "term       = $term<br>\n";
                           echo "mode       = $mode<br>\n";
                           echo "range      = $range<br>\n";
                           echo "order_by   = $order_by<br>\n";
                           echo "But no records were returned<br><br>\n";
		           echo "Please email the above error using The Comments/Help/Support link on the \n";
		           echo "left navigation bar.\n";
		           echo "</form>\n";
		           echo "</body></html>\n";
		           $ret_val = disconnect();
		           exit;
		         }#end if no records returned
                       $last_record_retrieved = $to + 1;
		     }#end if more than a single page
		   else #only a single page
		     {
                       $indiv_multiple_pages = 0;
                       $from                 = $last_record_retrieved;
                       $to                   = $num_of_indivs - 1;
                       $range                = "$from"."-"."$to";
		       $indiv_rec_list = tableJoin($table_name[0],$table_name[1],$database_id,$field_list,$term,$mode,$range,$order_by);
                       if (!is_array($indiv_rec_list))
		         {
		           $date = date('Y-m-d H:i:s');
		           echo "Error #262: $date<br>\n";
		           echo "Error in call to tableJoin from individual_search.php<br>\n";
		           echo "$indiv_rec_list<br><br>\n";
		           echo "Please email the above error using The Comments/Help/Support link on the \n";
		           echo "left navigation bar.\n";
		           echo "</form>\n";
		           echo "</body></html>\n";
		           $ret_val = disconnect();
		           exit;
		         }#end if (!is_array(indiv_rec_list))
                       if (sizeof($indiv_rec_list) == 0)
			 {
			   $date = date('Y-m-d H:i:s');
                           echo "Error #263: $date<br>\n";
		           echo "Error in call to individual_search.php<br>\n";
		           echo "There should be records returned for tableJoin search with parameters:<br>\n";
                           echo "table_name = ".join(',',$table_name)."<br>\n";
                           echo "field_list = ".join(',',$field_list)."<br>\n";
                           echo "term       = $term<br>\n";
                           echo "mode       = $mode<br>\n";
                           echo "range      = $range<br>\n";
                           echo "order_by   = $order_by<br>\n";
                           echo "But no records were returned<br><br>\n";
		           echo "Please email the above error using The Comments/Help/Support link on the \n";
		           echo "left navigation bar.\n";
		           echo "</form>\n";
		           echo "</body></html>\n";
		           $ret_val = disconnect();
		           exit;
		         }#end if no records returned
		     }#end else only a single page
		 }#end if tableJoin
	       if ($function_to_call == 'compoundTableQuery')
		 {
		   $num_of_indivs = countCompoundTableQuery($table_name,$database_id,$field_list,$term,$mode,$join);
		   if (!preg_match('/^\d+$/',$num_of_indivs))
		     {
		       $date = date('Y-m-d H:i:s');
		       echo "Error #264: $date<br>\n";
		       echo "Error in call to countCompoundTableQuery from individual_search.php<br>\n";
		       echo "$num_of_indivs<br><br>\n";
		       echo "Please email the above error using The Comments/Help/Support link on the \n";
		       echo "left navigation bar.\n";
		       echo "</form>\n";
		       echo "</body></html>\n";
		       $ret_val = disconnect();
		       exit;
		     }#end error in call to countCompoundTableQuery
                   $records_yet_to_be_retrieved = $num_of_indivs - $last_record_retrieved;

                   if ($records_yet_to_be_retrieved > $max_records_to_print_per_page)
                     {
                       $indiv_multiple_pages = 1;
                       $from                 = $last_record_retrieved;
                       $to                   = ($last_record_retrieved - 1) + $max_records_to_print_per_page;
                       $range                = "$from"."-"."$to";
                       $indiv_rec_list = compoundTableQuery($table_name,$database_id,$field_list,$term,$mode,$join,$range,$order_by);
                       if (!is_array($indiv_rec_list))
		         {
		           $date = date('Y-m-d H:i:s');
		           echo "Error #265: $date<br>\n";
		           echo "Error in call to compoundTableQuery from individual_search.php<br>\n";
		           echo "$indiv_rec_list<br><br>\n";
		           echo "Please email the above error using The Comments/Help/Support link on the \n";
		           echo "left navigation bar.\n";
		           echo "</form>\n";
		           echo "</body></html>\n";
		           $ret_val = disconnect();
		           exit;
		         }#end if (!is_array(indiv_rec_list))
                       if (sizeof($indiv_rec_list) == 0)
			 {
			   $date = date('Y-m-d H:i:s');
                           echo "Error #266: $date<br>\n";
		           echo "Error in call to individual_search.php<br>\n";
		           echo "There should be records returned for compoundTableQuery search with parameters:<br>\n";
                           echo "table_name = $table_name<br>\n";
                           echo "field_list = ".join(',',$field_list)."<br>\n";
                           echo "term       = ".join(',',$term)."<br>\n";
                           echo "mode       = ".join(',',$mode)."<br>\n";
                           echo "range      = $range<br>\n";
                           echo "order_by   = $order_by<br>\n";
                           echo "But no records were returned<br><br>\n";
		           echo "Please email the above error using The Comments/Help/Support link on the \n";
		           echo "left navigation bar.\n";
		           echo "</form>\n";
		           echo "</body></html>\n";
		           $ret_val = disconnect();
		           exit;
		         }#end if no records returned
		       $last_record_retrieved = $to + 1;
		     }#end if more than a single page
		   else #only a single page
		     {
                       $indiv_multiple_pages = 0;
                       $from                 = $last_record_retrieved;
                       $to                   = $num_of_indivs - 1;
                       $range                = "$from"."-"."$to";
		       $indiv_rec_list = compoundTableQuery($table_name,$database_id,$field_list,$term,$mode,$join,$range,$order_by);
                       if (!is_array($indiv_rec_list))
		         {
		           $date = date('Y-m-d H:i:s');
		           echo "Error #267: $date<br>\n";
		           echo "Error in call to compoundTableQuery from individual_search.php<br>\n";
		           echo "$indiv_rec_list<br><br>\n";
		           echo "Please email the above error using The Comments/Help/Support link on the \n";
		           echo "left navigation bar.\n";
		           echo "</form>\n";
		           echo "</body></html>\n";
		           $ret_val = disconnect();
		           exit;
		         }#end if (!is_array(indiv_rec_list))
                       if (sizeof($indiv_rec_list) == 0)
			 {
			   $date = date('Y-m-d H:i:s');
                           echo "Error #268: $date<br>\n";
		           echo "Error in call to individual_search.php<br>\n";
		           echo "There should be records returned for compoundTableQuery search with parameters:<br>\n";
                           echo "table_name = $table_name<br>\n";
                           echo "field_list = ".join(',',$field_list)."<br>\n";
                           echo "term       = ".join(',',$term)."<br>\n";
                           echo "mode       = ".join(',',$mode)."<br>\n";
                           echo "range      = $range<br>\n";
                           echo "order_by   = $order_by<br>\n";
                           echo "But no records were returned<br><br>\n";
		           echo "Please email the above error using The Comments/Help/Support link on the \n";
		           echo "left navigation bar.\n";
		           echo "</form>\n";
		           echo "</body></html>\n";
		           $ret_val = disconnect();
		           exit;
		         }#end if no records returned
		     }#end else only a single page
		 }#end if compoundTableQuery


	       $ret_val = printLogOutButton('individual_search.php');
               echo "<br><br>\n\n";

	       if ($indiv_multiple_pages) 
		 {
                   echo "<table align=\"center\">\n";
                   echo "<form action=\"download.php\" name=\"download_form1\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";
                   echo "<input type=\"hidden\" name=\"type_of_download\" value=\"individual_record\">\n";
                   echo "<input type=\"hidden\" name=\"indiv_id\" value=\"\">\n";
                   echo "<tr>\n";
                   echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Selected Individual's Information\" onClick=\"copyData('download_form1')\"></td>\n";
                   echo "</form>\n\n";

                   echo "<form action=\"individual_search.php\" name=\"skip_form1\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";
                   echo "<input type=\"hidden\" name=\"individual_flag\" value=\"1\">\n";
                   echo "<input type=\"hidden\" name=\"indiv_multiple_pages\" value=\"0\">\n";
                   echo "<input type=\"hidden\" name=\"indiv_id\" value=\"\">\n";
                   echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes for Selected Individuals\" onClick=\"copyData('skip_form1')\"></td>\n";
                   echo "</form>\n";
                   echo "</tr>\n\n";

                   echo "<form action=\"individual_search.php\" name=\"form\" method=\"POST\" target=\"main\">\n";
		   $records_left = ($num_of_indivs - $last_record_retrieved );
                   echo "<tr>\n";
		   if ($records_left > $max_records_to_print_per_page)
                     {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Next $max_records_to_print_per_page Individuals\"></td>\n";}
		   else
                     {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Next $records_left Individuals\"></td>\n";}
                   echo "<td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Reset Selections\"></td>\n";
                   echo "</tr>\n";
                   echo "</table>\n";
		 }#end multiple pages
	       else #only one page
	         {
                   echo "<table align=\"center\">\n";
                   echo "<tr>\n";
                   echo "<form action=\"download.php\" name=\"download_form1\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";
                   echo "<input type=\"hidden\" name=\"type_of_download\" value=\"individual_record\">\n";
                   echo "<input type=\"hidden\" name=\"indiv_id\" value=\"\">\n";
                   echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Selected Individual's Information\" onClick=\"copyData('download_form1')\"></td>\n";
                   echo "</form>\n\n";

                   echo "<form action=\"individual_search.php\" name=\"form\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(this))\">\n";
		   echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes for Selected Individuals\"></td>\n";
                   echo "</tr>\n";
                   echo "</table>\n";
                   echo "<br>\n";

                   echo "<table align=\"center\">\n";
                   echo "<tr>\n";
                   echo "<td align=\"center\">&nbsp;</td>\n";
                   echo "<td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Deselect Selections\"></td>\n";
                   echo "</tr>\n";
                   echo "</table>\n";
		 }
               echo "<br><br>\n\n";

               $jscript = printIndividualCheckList($indiv_rec_list,$database_id);
	       if ($jscript == '0')
                 {
                   $date = date('Y-m-d H:i:s');
		   echo "Error #269: $date<br>\n";
		   echo "Error in call to printIndividualCheckList from individual_search.php<br>\n";
		   echo "See above error message from printIndividualCheckList for an explanation<br><br>\n";
		   echo "Please email the above error using the Comments/Help/Support link on the \n";
		   echo "left navigation bar.\n";
		   echo "</form>\n";
		   echo "</body></html>\n";
		   $ret_val = disconnect();
		   exit;
		 }#end if (jscript == '0')
               echo "<br><br>\n";

               echo "<input type=\"hidden\" name=\"individual_flag\" value=\"1\">\n";
               echo "<input type=\"hidden\" name=\"indiv_multiple_pages\" value=\"$indiv_multiple_pages\">\n";
               if (sizeof($individual_ids) > 0)#if have ids from previous page(s)
                 {
                   if (!is_array($individual_ids)) 
                     {if (preg_match('/\d+/',$individual_ids)){echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$individual_ids\">\n";}}
	           else
                     {
		       foreach ($individual_ids as $indiv_id)
                         {
		           echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$indiv_id\">\n";
		         }#end foreach (indiv_ids as indiv_id)
		     }#end else sizeof(indiv_ids) != '1'
                 }#end if have ids from previous page(s)

               if ($indiv_multiple_pages)
                 {
                   echo "<input type=\"hidden\" name=\"function_to_call\" value=\"$function_to_call\">\n";

                   if ($function_to_call == 'tableJoin') {foreach ($table_name as $name){echo "<input type=\"hidden\" name=\"table_name[]\" value=\"$name\">\n";}}
                   else                                  {echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";}

		   foreach ($field_list as $field){echo "<input type=\"hidden\" name=\"field_list[]\" value=\"$field\">\n";}

                   if (is_array($term)){foreach ($term as $s_term){echo "<input type=\"hidden\" name=\"term[]\" value=\"$s_term\">\n";}}
                   else {echo "<input type=\"hidden\" name=\"term\" value=\"$term\">\n";}

                   if (is_array($mode)){foreach ($final_mode as $s_mode){echo "<input type=\"hidden\" name=\"mode[]\" value=\"$s_mode\">\n";}}
                   else {echo "<input type=\"hidden\" name=\"mode\" value=\"$mode\">\n";}

                   if ($final_function_call == 'compoundTableQuery') {echo "<input type=\"hidden\" value=\"join\" value=\"$join\">\n";}

                   echo "<input type=\"hidden\" name=\"order_by\" value=\"$order_by\">\n";
                   echo "<input type=\"hidden\" name=\"last_record_retrieved\" value=\"$last_record_retrieved\">\n";

                   echo "<table align=\"center\">\n";
                   echo "<tr>\n";
                   echo "<td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Deselect Selections\"></td>\n";
		   if ($records_left > $max_records_to_print_per_page)
                     {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Next $max_records_to_print_per_page Individual Records\"></td>\n";}
		   else
                     {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get next $records_left Individual Records\"></td>\n";}
                   echo "</form>\n";
                   echo "</tr>\n";

                   echo "<form action=\"download.php\" name=\"download_form2\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";
                   echo "<input type=\"hidden\" name=\"type_of_download\" value=\"individual_record\">\n";
                   echo "<input type=\"hidden\" name=\"indiv_id\" value=\"\">\n";
                   echo "<tr>\n";
                   echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Selected Individual's Information\" onClick=\"copyData('download_form2')\"></td>\n";
                   echo "</form>\n";

                   echo "<form action=\"individual_search.php\" name=\"skip_form2\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";
                   echo "<input type=\"hidden\" name=\"individual_flag\" value=\"1\">\n";
                   echo "<input type=\"hidden\" name=\"indiv_multiple_pages\" value=\"0\">\n";
                   echo "<input type=\"hidden\" name=\"indiv_id\" value=\"\">\n";
                   echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes for Selected Individuals\" onClick=\"copyData('skip_form2')\"></td>\n";
                   echo "</form>\n";
                   echo "</tr>\n\n";
                   echo "</table>\n";
		 }#end if have multiple pages of results to display
	       else #only one page of results
	         {
                   echo "<table>\n";
                   echo "<tr>\n";
                   echo "<td align=\"center\">&nbsp;</td>\n";
                   echo "<td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Deselect Selections\"></td>\n";
                   echo "</tr>\n";
                   echo "</table>\n";
                   echo "<br>\n";
                   echo "<table align=\"center\">\n";
                   echo "<tr>\n";
	           echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes for Selected Individuals\"></td>\n";
                   echo "</form>\n\n";

                   echo "<form action=\"download.php\" name=\"download_form2\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";
                   echo "<input type=\"hidden\" name=\"type_of_download\" value=\"individual_record\">\n";
                   echo "<input type=\"hidden\" name=\"indiv_id\" value=\"\">\n";
                   echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Selected Individual's Information\" onClick=\"copyData('download_form2')\"></td>\n";
                   echo "</form>\n";
                   echo "</tr>\n";
                   echo "</table>\n";
	         }#end else only one page of results
	       echo "<br><br>\n\n";

               $ret_val = printLogOutButton('individual_search.php');
	       echo "\n\n";

	       echo "<script>\n";
	       echo "function Validate(form)\n";
               echo "$jscript\n";
               if (!$indiv_multiple_pages)
                 {
                   echo "\n";
                   echo "function copyData(form_to_copy_to)\n";
                   echo "{\n";
                   echo " var indiv_string = new Array();\n";
                   echo " var length = 0;\n";
                   echo " for (var i=0; i<document.form.elements['indiv_id[]'].length; i++){\n";
                   echo "   if (document.form.elements['indiv_id[]'][i].type == \"hidden\"){\n";
                   echo "     length = indiv_string.length;\n";
                   echo "     indiv_string[length] = document.form.elements['indiv_id[]'][i].value;}\n";
                   echo "   else{\n";
                   echo "     if (document.form.elements['indiv_id[]'][i].checked){\n";
                   echo "       length = indiv_string.length;\n";
                   echo "       indiv_string[length] = document.form.elements['indiv_id[]'][i].value;}}}\n";
                   echo " if (form_to_copy_to == \"skip_form1\"){\n";
                   echo "   document.skip_form1.indiv_id.value = indiv_string;}\n";
                   echo " if (form_to_copy_to == \"skip_form2\"){\n";
                   echo "   document.skip_form2.indiv_id.value = indiv_string;}\n";
                   echo " if (form_to_copy_to == \"download_form1\"){\n";
                   echo "   document.download_form1.indiv_id.value = indiv_string;}\n";
                   echo " if (form_to_copy_to == \"download_form2\"){\n";
                   echo "   document.download_form2.indiv_id.value = indiv_string;}\n";
                   echo "}\n";
                 }#end if download form on page
	       echo "</script>\n";
               unset($indiv_multiple_pages);
	     }#end if multiple pages of individual data to display

	   if (($individual_flag == '1') and
               (sizeof($individual_ids) > '0') and 
               ($indiv_multiple_pages == '0')
              )#All individuals have been selected, get status and markers
             {
	      #7  Select Status and Chromosomes of Markers
	      if ((!preg_match('/\w+/',$status)) and
		  (sizeof($chromosome_ids) == '0')
		 )
                {
		  echo "Please select the Status you want to investigate and the Chromosomes of the Markers you want genotypes for:<br><br>\n";
		  $ret_val = printLogOutButton('individual_search.php');
                  echo "<br>\n";

                  echo "<form action=\"individual_search.php\" name=\"form\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(this))\">\n";
                  echo "<center>\n";
		  echo "<input type=\"submit\" name=\"submit\" value=\"Get Markers from Selected Chromosomes\">\n";
                  echo "<input type=\"reset\" name=\"reset\" value=\"Deselect Selections\">\n";
                  echo "</center>\n";
                  echo "<br><br>\n";

                  echo "<table align=\"center\">\n";
                  echo "<tr>\n";
                  echo "<td><b>Affection Status:</b></td><td>\n";
                  $jscript_1 = printStatusSelectList($database_id);
                  if ($jscript_1 == '0')
		    {
                      echo "</td></tr>\n";
                      echo "</table>\n";
                      echo "<br><br>\n";

		      $date = date('Y-m-d H:i:s');
		      echo "Error #270: $date<br>\n";
		      echo "Error in call to printStatusSelectList from individual_search.php<br>\n";
		      echo "See the error message from printStatusSelectList above for an explanation.<br><br>\n";
		      echo "Please email the above error using The Comments/Help/Support link on the \n";
		      echo "left navigation bar.\n";
		      echo "</form>\n";
		      echo "</body></html>\n";
		      $ret_val = disconnect();
		      exit;
		    }#end error in call to printStatusSelectList
		  if ($jscript_1 == 'no_defined_statuses')
		    {
		      $date = date('Y-m-d H:i:s');
                      echo "<b>Continue without selecting a status</b>.<br>\n";
		      echo "This message was generated at $date\n";
		      echo "<input type=\"hidden\" name=\"status\" value=\"no_defined_statuses\">\n";
		    }#end if no statuses
                  echo "</td>\n";
                  echo "</tr>\n";
                  echo "</table>\n";
		  echo "<br><br>\n";

                  $field_list_array = array('marker_id');
                  if ($db_type == 'mysql'){$order_by = 'chromosome+0 ASC';}
                  if ($db_type == 'pgsql'){$order_by = "chromosome::text::integer ASC";}
		  $chr_id_array = distinctTableQuery('chromosome','marker_table',$database_id,$field_list_array,'_','wildcard','all',$order_by);
		  if (!is_array($chr_id_array))
		    {
		      $date = date('Y-m-d H:i:s');
		      echo "Error #271: $date<br>\n";
		      echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
		      echo "$chr_id_array<br><br>\n";
		      echo "Please email the above error using The Comments/Help/Support link on the \n";
		      echo "left navigation bar.\n";
		      echo "</form>\n";
		      echo "</body></html>\n";
		      $ret_val = disconnect();
		      exit;
		     }#end if (!is_array(chr_id_array))
		   if (sizeof($chr_id_array) == 0)
		     {
		       $date = date('Y-m-d H:i:s');
                       echo "</form>\n";#end form for individual_search.php
                       echo "<center>\n";
		       echo "<b>Currently, there are no markers in the database</b>.<br>\n";
                       echo "Therefore there are no genotypes for the individuals you selected.<br>\n";
		       echo "This message was generated at $date<br>\n";
                       echo "Continue to download the information on the Individuals you selected below:<br><br>\n";

		       echo "<form action=\"download.php\" name=\"download\" method=\"POST\" target=\"main\">\n";
		       echo "<input type=\"hidden\" name=\"type_of_download\" value=\"individual_record\">\n";
		       if (!is_array($individual_ids)) {echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$individual_ids\">\n";}
		       else
                         {
                           #echo "individual_ids is an array<br>\n";
                           $indiv_id_string = join($individual_ids,',');
                           echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$indiv_id_string\">\n";
		         }#end sizeof(indiv_ids) != '1'
		       echo "<input type=\"submit\" name=\"submit\" value=\"Download All Individuals' Information\">\n";
		       echo "</form>\n";
		       echo "</center>\n";
		       echo "</body></html>\n";
		       $ret_val = disconnect();
		       exit;
		     }#end if no chromosomes, and therefore no markers

		  $jscript_2 = printChromosomeCheckList($chr_id_array,$database_id);
                  if ($jscript_2 == '0')
		    {
		      $date = date('Y-m-d H:i:s');
		      echo "Error #272: $date<br>\n";
		      echo "Error in call to printChromosomeCheckList from individual_search.php<br>\n";
		      echo "See the error message from printChromosomeCheckList above for an explanation.<br><br>\n";
		      echo "Please email the above error using The Comments/Help/Support link on the \n";
		      echo "left navigation bar.\n";
		      echo "</form>\n";
		      echo "</body></html>\n";
		      $ret_val = disconnect();
		      exit;
		    }#end error in call to printChromosomeCheckList
		  echo "<br><br>\n";

		  if ($jscript_1 == 'no_defined_statuses') {$jscript = $jscript_2;}
		  else
		    {
		      $jscript_1 = preg_replace('/ else \{return true;\}
\}/','',$jscript_1);
		      $jscript_2 = preg_replace('/^\{
/','',$jscript_2);
		      $jscript = "$jscript_1\n$jscript_2";
		    }#end else have statuses

		  echo "<input type=\"hidden\" name=\"individual_flag\" value=\"1\">\n";
		  echo "<input type=\"hidden\" name=\"indiv_multiple_pages\" value=\"$indiv_multiple_pages\">\n";
		  if (!is_array($individual_ids)) {echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$individual_ids\">\n";}
		  else
		    {
		      $indiv_id_string = join($individual_ids,',');
		      echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$indiv_id_string\">\n";
                      unset($indiv_id_string);
		    }#end individual_ids is an array

		  echo "<center>\n";
		  echo "<input type=\"submit\" name=\"submit\" value=\"Get Markers from Selected Chromosomes\">\n";
                  echo "<input type=\"reset\" name=\"reset\" value=\"Deselect Selections\">\n";
		  echo "</form>\n";
                  echo "</center>\n";
                  echo "<br><br>\n";

		  $ret_val = printLogOutButton('individual_search.php');
                  echo "\n\n";

                  echo "<script>\n";
		  echo "function Validate(form)\n";
		  echo "$jscript\n";
		  echo "</script>\n";
		}#end if have individual ids, but no status or chromosomes

              #if you have individual ids, status, and chromosomes of markers, but haven't investigated markers yet
	      if ((preg_match('/\w+/',$status)) and
		  (sizeof($chromosome_ids) > '0') and
		  (!preg_match('/\d/',$marker_multiple_pages))
		  )
		{
                 echo "Please Select the markers you would like genotypes for:<br><br>\n";

                 if (is_array($chromosome_ids)) {$search_term = join($chromosome_ids,',');}
                 else                           {$search_term = $chromosome_ids;}
                 $field_list_array = array('chromosome');

                 $num_of_markers = countTableQuery('marker_table',$database_id,$field_list_array,$search_term,'in');
                 if (!preg_match('/^\d+$/',$num_of_markers))
                   {
                     $date = date('Y-m-d H:i:s');
		     echo "Error #273: $date<br>\n";
		     echo "Error in call to countTableQuery from individual_search.php<br>\n";
		     echo "$num_of_markers<br><br>\n";
		     echo "Please email the above error using The Comments/Help/Support link on the \n";
		     echo "left navigation bar.\n";
		     echo "</form>\n";
		     echo "</body></html>\n";
		     $ret_val = disconnect();
		     exit;
		   }#end error in call to countTableQuery

		 if ($num_of_markers == 0)
		   {
		     $date = date('Y-m-d H:i:s');
		     echo "<center>\n";
		     echo "Currently there are no markers in the database.<br>\n";
		     echo "This message was generated at $date<br>\n";
		     echo "Continue to download the information on the Individuals you selected below:<br><br>\n";

		     echo "<form action=\"download.php\" name=\"download\" method=\"POST\" target=\"main\">\n";
		     echo "<input type=\"hidden\" name=\"type_of_download\" value=\"individual_record\">\n";
		     if (!is_array($individual_ids)) {echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$individual_ids\">\n";}
		     else
                       {
                         $indiv_id_string = join($individual_ids,',');
                         echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$indiv_id_string\">\n";
		       }#end sizeof(indiv_ids) != '1'
		     echo "<input type=\"submit\" name=\"submit\" value=\"Download All Individuals' Information\">\n";
		     echo "</form>\n";
		     echo "</center>\n";
                     echo "</body></html>\n";
		     $ret_val = disconnect();
		     exit;
		   }
                 echo "There are $num_of_markers Markers in the database for Chromosome(s) $search_term.<br><br>\n";

                 if ($num_of_markers > ($max_records_to_print_per_page * 5))
		   {
                     echo"<hr>\n";
                     echo"<br>\n";
		     echo "If you would like to get genotypes for all the markers on the chromosomes you've selected, \n";
		     echo "without having to investigate which markers you want:<br><br> \n";
		     echo "Click the \"Get All Genotypes Without Phenotypes\" button if you <b>do not want</b> any phenotype values<br><br> ";
		     echo "Click the \"Get All Genotypes & Select Phenotypes\" button if you <b>do want</b> phenotype values.<br><br>\n";

		     echo "<form action=\"individual_search.php\" name=\"all_marker_form\" method=\"POST\" target=\"main\">\n";
                     echo "<input type=\"hidden\" name=\"status\" value=\"$status\">\n";
                     echo "<input type=\"hidden\" name=\"individual_flag\" value=\"1\">\n";
		     echo "<input type=\"hidden\" name=\"indiv_multiple_pages\" value=\"0\">\n";
		     if (!is_array($individual_ids)) {echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$individual_ids\">\n";}
		     else
                       {
                         $indiv_id_string = "";
		         foreach ($individual_ids as $indiv_id)
                           {
		             $indiv_id_string.= "$indiv_id,";
		           }#end foreach (indiv_ids as indiv_id)
                         $indiv_id_string = preg_replace('/,$/','',$indiv_id_string);
                         echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$indiv_id_string\">\n";
		       }#end sizeof(indiv_ids) != '1'

                     if ($db_type == 'mysql'){$order_by = 'chromosome+0,chromosome_position ASC';}
                     if ($db_type == 'pgsql'){$order_by = "chromosome::text::integer,chromosome_position ASC";}
		     $marker_id_array = distinctTableQuery('marker_id','marker_table',$database_id,$field_list_array,$search_term,'in','all',$order_by);
		     if (!is_array($marker_id_array))
		       {
			 $date = date('Y-m-d H:i:s');
			 echo "Error #274: $date<br>\n";
			 echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
			 echo "$marker_id_array<br><br>\n";
			 echo "Please email the above error using The Comments/Help/Support link on the \n";
			 echo "left navigation bar.\n";
			 echo "</form>\n";
			 echo "</body></html>\n";
			 $ret_val = disconnect();
			 exit;
		       }#end if error in call to distinctTableQuery
                     $marker_id_string = join($marker_id_array,',');
		     echo "<input type=\"hidden\" name=\"marker_multiple_pages\" value=\"0\">\n";
		     echo "<input type=\"hidden\" name=\"marker_id[]\" value=\"$marker_id_string\">\n";
                     unset($marker_id_array);
                     unset($marker_id_string);

		     echo "<center>\n";
		     echo "<input type=\"submit\" name=\"submit\" value=\"Get All Genotypes without Phenotypes\">\n";
		     echo "<input type=\"submit\" name=\"submit\" value=\"Get All Genotypes & Select Phenotypes\">\n";
		     echo "</center>\n";
		     echo "</form>\n";
		     echo "<br><br>\n";
                     echo "<hr>\n";
                     echo "<br>\n";
                     echo "Or Continue below to individually select which Markers to Investigate.<br><br>\n";
		   }#end if more than 5 pages of markers markers

                 if ($num_of_markers > $max_records_to_print_per_page)
		   {
                     $marker_multiple_pages = 1;
		     $from                  = "0";
                     $to                    = $max_records_to_print_per_page - 1;
                     $range                 = "$from"."-"."$to";
                     $marker_rec_list = tableQuery('marker_table',$database_id,$field_list_array,$search_term,'in',$range,$order_by);
		     if (!is_array($marker_rec_list))
		       {
			 $date = date('Y-m-d H:i:s');
			 echo "Error #275: $date<br>\n";
			 echo "Error in call to tableQuery from individual_search.php<br>\n";
			 echo "$marker_rec_list<br><br>\n";
			 echo "Please email the above error using The Comments/Help/Support link on the \n";
			 echo "left navigation bar.\n";
			 echo "</form>\n";
			 echo "</body></html>\n";
			 $ret_val = disconnect();
			 exit;
		       }#end if (!is_array(marker_rec_list))
		     if (sizeof($marker_rec_list) == 0)
		       {
			 $date = date('Y-m-d H:i:s');
			 echo "<b>Currently, there are no markers in the database</b>.<br>\n";
			 echo "Therefore there are no genotypes for the individuals you selected.<br>\n";
			 echo "This message was generated at $date<br>\n";
			 echo "</body></html>\n";
			 $ret_val = disconnect();
			 exit;
		       }
		     $final_function_call   = 'tableQuery';
                     $final_table_name      = 'marker_table';
                     $final_field_list      = $field_list_array;
                     $final_term            = $search_term;
                     $final_mode            = 'in';
                     $final_order_by        = $order_by;
                     $last_record_retrieved = $max_records_to_print_per_page;
		   }#end if more than a single page
		 else #only a single page
		   {
                     $marker_multiple_pages = 0;
                     $range                 = "all";
                     if ($db_type == 'mysql'){$order_by = 'chromosome+0,chromosome_position ASC';}
                     if ($db_type == 'pgsql'){$order_by = "chromosome::text::integer,chromosome_position ASC";}
		     $marker_rec_list = tableQuery('marker_table',$database_id,$field_list_array,$search_term,'in',$range,$order_by);
		     if (!is_array($marker_rec_list))
		       {
			 $date = date('Y-m-d H:i:s');
			 echo "Error #276: $date<br>\n";
			 echo "Error in call to tableQuery from individual_search.php<br>\n";
			 echo "$marker_rec_list<br><br>\n";
			 echo "Please email the above error using The Comments/Help/Support link on the \n";
			 echo "left navigation bar.\n";
			 echo "</form>\n";
			 echo "</body></html>\n";
			 $ret_val = disconnect();
			 exit;
		       }#end if (!is_array(marker_rec_list))
		     if (sizeof($marker_rec_list) == 0)
		       {
			 $date = date('Y-m-d H:i:s');
			 echo "<b>Currently, there are no markers in the database</b>.<br>\n";
			 echo "Therefore there are no genotypes for the individuals you selected.<br>\n";
			 echo "This message was generated at $date<br>\n";
			 echo "</body></html>\n";
			 $ret_val = disconnect();
			 exit;
		       }
		   }#end else only a single page

		 $ret_val = printLogOutButton('individual_search.php');
                 echo "<br><br>\n\n";

                 if ($marker_multiple_pages)
		   {
                     echo "<table align=\"center\">\n";
                     echo "<form action=\"individual_search.php\" name=\"skip_form1\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";
                     echo "<input type=\"hidden\" name=\"status\" value=\"$status\">\n";
                     echo "<input type=\"hidden\" name=\"individual_flag\" value=\"1\">\n";
		     echo "<input type=\"hidden\" name=\"indiv_multiple_pages\" value=\"0\">\n";
		     if (!is_array($individual_ids)) {echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$individual_ids\">\n";}
		     else
                       {
                         $indiv_id_string = join($individual_ids,',');
                         echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$indiv_id_string\">\n";
                         unset($indiv_id_string);
		       }#end else it is an array
                     echo "<input type=\"hidden\" name=\"marker_multiple_pages\" value=\"0\">\n";
                     echo "<input type=\"hidden\" name=\"marker_id\" value=\"\">\n"; 
                     echo "<tr>\n";
                     echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes without Phenotypes\" onClick=\"copyData('skip_form1')\"></td>\n";
                     echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Select Phenotypes\" onClick=\"copyData('skip_form1')\"></td>\n";
                     echo "</form>\n";
                     echo "</tr>\n";

                     echo "<form action=\"individual_search.php\" name=\"form\" method=\"POST\" target=\"main\">\n";
                     echo "<tr>\n";
		     $records_left = ($num_of_markers - $last_record_retrieved);
		     if ($records_left > $max_records_to_print_per_page)
                       {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Next $max_records_to_print_per_page Markers\"></td>\n";}
		     else
                       {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Next $records_left Markers\"></td>\n";}
                     echo "<td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Deselect Selections\"></td>\n";
                     echo "</tr>\n";
                     echo "</table>\n\n";
		   }#end if more than a single page
		 else #only a single page
		   {
                     echo "<table align=\"center\">\n";
                     echo "<form action=\"individual_search.php\" name=\"form\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(this))\">\n";
                     echo "<tr>\n";
		     echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes without Phenotypes\"></td>\n";
		     echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Select Phenotypes\"></td>\n";
                     echo "</tr>\n";
                     echo "</table>\n";
                     echo "<br>\n";

                     echo "<table align=\"center\">\n";
                     echo "<tr>\n";
                     echo "<td align=\"center\">&nbsp;</td>\n";
                     echo "<td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Deselect Selections\"></td>\n";
                     echo "</tr>\n";
                     echo "</table>\n";
		   }#end else only a single page
                 echo "<br><br>\n";

		 $jscript = printMarkerCheckList($marker_rec_list);
		 if ($jscript == '0')
                   {
		     $date = date('Y-m-d H:i:s');
		     echo "Error #277: $date<br>\n";
		     echo "Error in call to printMarkerCheckList from individual_search.php<br>\n";
		     echo "See above error message from printMarkerCheckList for an explanation.<br><br>\n";
		     echo "Please email the above error using The Comments/Help/Support link on the \n";
		     echo "left navigation bar. \n";
		     echo "</form>\n";
		     echo "</body></html>\n";
		     $ret_val = disconnect();
		     exit;
		   }#end if (jscript == '0')
                 echo "<br><br>\n";

                 echo "<input type=\"hidden\" name=\"status\" value=\"$status\">\n";
                 echo "<input type=\"hidden\" name=\"individual_flag\" value=\"1\">\n";
		 echo "<input type=\"hidden\" name=\"indiv_multiple_pages\" value=\"0\">\n";
		 if (!is_array($individual_ids)) {echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$individual_ids\">\n";}
		 else
                   {
                     $indiv_id_string = join($individual_ids,',');
                     echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$indiv_id_string\">\n";
                     unset($indiv_id_string);
		   }#end else sizeof(indiv_ids) != '1'
                 echo "<input type=\"hidden\" name=\"marker_multiple_pages\" value=\"$marker_multiple_pages\">\n";

		 if ($marker_multiple_pages)
		   {
		     echo "<input type=\"hidden\" name=\"function_to_call\" value=\"$final_function_call\">\n";
		     if ($final_function_call == 'tableJoin') 
                       {
                         foreach ($final_table_name as $name) {echo "<input type=\"hidden\" name=\"table_name[]\" value=\"$name\">\n";}
                       }
                     else{echo "<input type=\"hidden\" name=\"table_name\" value=\"$final_table_name\">\n";}

		     foreach ($final_field_list as $field){echo "<input type=\"hidden\" name=\"field_list[]\" value=\"$field\">\n";}

                     if (is_array($final_term)){foreach ($final_term as $term){echo "<input type=\"hidden\" name=\"term[]\" value=\"$term\">\n";}}
                     else {echo "<input type=\"hidden\" name=\"term\" value=\"$final_term\">\n";}

                     if (is_array($final_mode)){foreach ($final_mode as $mode){echo "<input type=\"hidden\" name=\"mode[]\" value=\"$mode\">\n";}}
                     else {echo "<input type=\"hidden\" name=\"mode\" value=\"$final_mode\">\n";}

                     if ($final_function_call == 'compoundTableQuery') {echo "<input type=\"hidden\" value=\"join\" value=\"$final_join\">\n";}

                     echo "<input type=\"hidden\" name=\"order_by\" value=\"$final_order_by\">\n";
                     echo "<input type=\"hidden\" name=\"last_record_retrieved\" value=\"$last_record_retrieved\">\n";

                     echo "<table align=\"center\">\n";
                     echo "<tr>\n";
                     echo "<td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Deselect Selections\"></td>\n";
                     if ($records_left > $max_records_to_print_per_page)
                       {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Next $max_records_to_print_per_page Markers\"></td>\n";}
		     else
                       {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Next $records_left Markers\"></td>\n";}
                     echo "</tr>\n";
                     echo "</form>\n\n";

                     echo "<form action=\"individual_search.php\" name=\"skip_form2\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";
                     echo "<input type=\"hidden\" name=\"status\" value=\"$status\">\n";
                     echo "<input type=\"hidden\" name=\"individual_flag\" value=\"1\">\n";
		     echo "<input type=\"hidden\" name=\"indiv_multiple_pages\" value=\"0\">\n";
		     if (!is_array($individual_ids)) {echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$individual_ids\">\n";}
		     else
                       {
                         $indiv_id_string = join($individual_ids,',');
                         echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$indiv_id_string\">\n";
                         unset($indiv_id_string);
		       }#end else it is an array
                     echo "<input type=\"hidden\" name=\"marker_multiple_pages\" value=\"0\">\n";
                     echo "<input type=\"hidden\" name=\"marker_id\" value=\"\">\n"; 
                     echo "<tr>\n";
                     echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes without Phenotypes\" onClick=\"copyData('skip_form2')\"></td>\n";
                     echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Select Phenotypes\" onClick=\"copyData('skip_form2')\"></td>\n";
                     echo "</form>\n";
                     echo "</tr>\n";
                     echo "</table>\n";
		   }#end have multiple pages to display
		 else #only have one page of markers to display
		   {
                     echo "<table align=\"center\">\n";
                     echo "<tr>\n";
                     echo "<td align=\"center\">&nbsp;</td>\n";
                     echo "<td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Deselect Selections\"></td>\n";
                     echo "</tr>\n";
                     echo "</table>\n";
                     echo "<br>\n";

                     echo "<table align=\"center\">\n";
                     echo "<tr>\n";
		     echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes without Phenotypes\"></td>\n";
		     echo "<td algin=\"center\"><input type=\"submit\" name=\"submit\" value=\"Select Phenotypes\"></td>\n";
                     echo "</form>\n";
                     echo "</tr>\n";
                     echo "</table>\n";
		   }
                 echo "<br><br>\n\n";

                 $ret_val = printLogOutButton('individual_search.php');
		 echo "\n\n";
		 
		 
                 echo "<script>\n";
		 echo "function Validate(form)\n";
		 echo "$jscript\n";
		 if ($marker_multiple_pages)
                   {
                     echo "\n";
                     echo "function copyData(form_to_copy_to)\n";
                     echo "{\n";
                     echo " var marker_string = new Array();\n";
                     echo " var length = 0;\n";
                     echo " for (var i=0; i<document.form.elements['marker_id[]'].length; i++){\n";
                     echo "   if (document.form.elements['marker_id[]'][i].checked){\n";
                     echo "     length = marker_string.length;\n";
                     echo "     marker_string[length] = document.form.elements['marker_id[]'][i].value;}}\n";
                     echo " if (form_to_copy_to == \"skip_form1\"){\n";
                     echo "   document.skip_form1.marker_id.value = marker_string;}\n";
                     echo " if (form_to_copy_to == \"skip_form2\"){\n";
                     echo "   document.skip_form2.marker_id.value = marker_string;}\n";
                     echo "}\n";
                   }#end if more than a single page
		 echo "</script>\n";
                 unset($marker_multiple_pages);
	        }#end if have individual ids, status, and chromosomes but haven't invesitaged markers yet

              #if have individual ids, status, but haven't finished investigating all the markers yet
	      if ((preg_match('/\w+/',$status)) and
		  ($marker_multiple_pages == '1')
		 )
		{
		  echo "Select the Markers you want genotypes for:<br><br>\n";

                  if ($function_to_call == 'tableQuery')
		    {
		      $num_of_markers = countTableQuery($table_name,$database_id,$field_list,$term,$mode);
		      if (!preg_match('/^\d+$/',$num_of_markers))
			{
			  $date = date('Y-m-d H:i:s');
			  echo "Error #278: $date<br>\n";
			  echo "Error in call to countTableQuery from individual_search.php<br>\n";
			  echo "$num_of_markers<br><br>\n";
			  echo "Please email the above error using The Comments/Help/Support link on the \n";
			  echo "left navigation bar.\n";
			  echo "</form>\n";
			  echo "</body></html>\n";
			  $ret_val = disconnect();
			  exit;
			}#end error in call to countTableQuery
		      $records_yet_to_be_retrieved = $num_of_markers - $last_record_retrieved;

		      if ($records_yet_to_be_retrieved > $max_records_to_print_per_page)
			{
                          $marker_multiple_pages = 1;
			  $from                  = $last_record_retrieved;
			  $to                    = ($last_record_retrieved-1) + $max_records_to_print_per_page;
			  $range                 = "$from"."-"."$to";
			  $marker_rec_list = tableQuery($table_name,$database_id,$field_list,$term,$mode,$range,$order_by);
			  if (!is_array($marker_rec_list))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #279: $date<br>\n";
			      echo "Error in call to tableQuery from individual_search.php<br>\n";
			      echo "$marker_rec_list<br><br>\n";
			      echo "Please email the above error using The Comments/Help/Support link on the \n";
			      echo "left navigation bar.\n";
			      echo "</form>\n";
			      echo "</body></html>\n";
			      $ret_val = disconnect();
			      exit;
			    }#end if (!is_array(marker_rec_list))
			  if (sizeof($marker_rec_list) == 0)
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #280: $date<br>\n";
			      echo "Error in call to individual_search.php<br>\n";
			      echo "There should be records returned for tableQuery search with parameters:<br>\n";
			      echo "table_name = $table_name<br>\n";
			      echo "field_list = ".join(',',$field_list)."<br>\n";
			      echo "term       = $term<br>\n";
			      echo "mode       = $mode<br>\n";
			      echo "range      = $range<br>\n";
			      echo "order_by   = $order_by<br>\n";
			      echo "But no records were returned<br><br>\n";
			      echo "Please email the above error using The Comments/Help/Support link on the \n";
			      echo "left navigation bar.\n";
			      echo "</form>\n";
			      echo "</body></html>\n";
			      $ret_val = disconnect();
			      exit;
			    }#end if no records returned
                          $last_record_retrieved = $to + 1;
			}#end if more than a single page
		      else #only a single page
			{
                          $marker_multiple_pages = 0;
			  $from                  = $last_record_retrieved;
			  $to                    = $num_of_markers - 1;
			  $range                 = "$from"."-"."$to";
			  $marker_rec_list = tableQuery($table_name,$database_id,$field_list,$term,$mode,$range,$order_by);
			  if (!is_array($marker_rec_list))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #281: $date<br>\n";
			      echo "Error in call to tableQuery from individual_search.php<br>\n";
			      echo "$marker_rec_list<br><br>\n";
			      echo "Please email the above error using The Comments/Help/Support link on the \n";
			      echo "left navigation bar.\n";
			      echo "</form>\n";
			      echo "</body></html>\n";
			      $ret_val = disconnect();
			      exit;
			    }#end if (!is_array(indiv_rec_list))
			  if (sizeof($marker_rec_list) == 0)
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #282: $date<br>\n";
			      echo "Error in call to individual_search.php<br>\n";
			      echo "There should be records returned for tableQuery search with parameters:<br>\n";
			      echo "table_name = $table_name<br>\n";
			      echo "field_list = ".join(',',$field_list)."<br>\n";
			      echo "term       = $term<br>\n";
			      echo "mode       = $mode<br>\n";
			      echo "range      = $range<br>\n";
			      echo "order_by   = $order_by<br>\n";
			      echo "But no records were returned<br><br>\n";
			      echo "Please email the above error using The Comments/Help/Support link on the \n";
			      echo "left navigation bar.\n";
			      echo "</form>\n";
			      echo "</body></html>\n";
			      $ret_val = disconnect();
			      exit;
			    }#end if no records returned
		        }#end else only a single page
		    }#end if tableQuery

		  $ret_val = printLogOutButton('individual_search.php');
                  echo "<br><br>\n";

		  if ($marker_multiple_pages)
		    {
                      echo "<table align=\"center\">\n";
                      echo "<form action=\"individual_search.php\" name=\"skip_form1\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";
                      echo "<input type=\"hidden\" name=\"status\" value=\"$status\">\n";
                      echo "<input type=\"hidden\" name=\"individual_flag\" value=\"1\">\n";
		      echo "<input type=\"hidden\" name=\"indiv_multiple_pages\" value=\"0\">\n";
		      if (!is_array($individual_ids)) {echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$individual_ids\">\n";}
		      else
                        {
                          $indiv_id_string = join($individual_ids,',');
                          echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$indiv_id_string\">\n";
                          unset($indiv_id_string);
		        }#end else sizeof(indiv_ids) != '1'
                      echo "<input type=\"hidden\" name=\"marker_multiple_pages\" value=\"0\">\n";
                      echo "<input type=\"hidden\" name=\"marker_id\" value=\"\">\n";
                      echo "<tr>\n";
                      echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes without Phenotypes\" onClick=\"copyData('skip_form1')\"></td>\n";
                      echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Select Phenotypes\" onClick=\"copyData('skip_form1')\"></td>\n";
                      echo "</form>\n";
                      echo "</tr>\n\n";

		      echo "<form action=\"individual_search.php\" name=\"form\" method=\"POST\" target=\"main\">\n";
		      $records_left = ($num_of_markers - $last_record_retrieved );
                      echo "<tr>\n";
		      if ($records_left > $max_records_to_print_per_page) 
                        {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Next $max_records_to_print_per_page Markers\"></td>\n";}
		      else
                        {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Next $records_left Markers\"></td>\n";}
		      echo "<td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Deselect Selections\"></td>\n";
                      echo "</tr>\n";
                      echo "</table>\n";
		    }#end multiple pages
		  else #only one page
		    {
                      echo "<table align=\"center\">\n";
		      echo "<form action=\"individual_search.php\" name=\"form\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(this))\">\n";
                      echo "<tr>\n";
		      echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes without Phenotypes\"></td>\n";
		      echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Select Phenotypes\"></td>\n";
                      echo "</tr>\n";
                      echo "</table>\n";
                      echo "<br>\n";

                      echo "<table align=\"center\">\n";
                      echo "<tr>\n";
                      echo "<td align=\"center\">&nbsp;</td>\n";
                      echo "<td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Deselect Selections\"></td>\n";
                      echo "</tr>\n";
                      echo "</table>\n";
		    }#end only one page of markers
                  echo "<br><br>\n";

		  $jscript = printMarkerCheckList($marker_rec_list);
		  if ($jscript == '0')
                    {
		      $date = date('Y-m-d H:i:s');
		      echo "Error #283: $date<br>\n";
		      echo "Error in call to printMarkerCheckList from individual_search.php<br>\n";
		      echo "See above error message from printMarkerCheckList for an explanation.<br><br>\n";
		      echo "Please email the above error using The Comments/Help/Support link on the \n";
		      echo "left navigation bar. \n";
		      echo "</form>\n";
		      echo "</body></html>\n";
		      $ret_val = disconnect();
		      exit;
		    }#end if (jscript == '0')
                  echo "<br><br>\n";

                  echo "<input type=\"hidden\" name=\"status\" value=\"$status\">\n";
                  echo "<input type=\"hidden\" name=\"individual_flag\" value=\"1\">\n";
		  echo "<input type=\"hidden\" name=\"indiv_multiple_pages\" value=\"0\">\n";
		  if (!is_array($individual_ids)) {echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$individual_ids\">\n";}
		  else
                    {
                      $indiv_id_string = join($individual_ids,',');
                      echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$indiv_id_string\">\n";
                      unset($indiv_id_string);
		    }#end else sizeof(indiv_ids) != '1'

		  echo "<input type=\"hidden\" name=\"marker_multiple_pages\" value=\"$marker_multiple_pages\">\n";
		  if (sizeof($marker_ids) > 0)
                    {
                      if (!is_array($marker_ids)) {echo "<input type=\"hidden\" name=\"marker_id[]\" value=\"$marker_ids\">\n";}
		      else
		        {
                          $marker_id_string = join($marker_ids,',');
                          echo "<input type=\"hidden\" name=\"marker_id[]\" value=\"$marker_id_string\">\n";
                          unset($marker_id_string);
		        }#end else marker ids is an array
                    }#end if have ids from previous page(s)

		  if ($marker_multiple_pages)
		    {
		      echo "<input type=\"hidden\" name=\"function_to_call\" value=\"$function_to_call\">\n";
		      if ($function_to_call == 'tableJoin') 
			{
			  foreach ($table_name as $name) {echo "<input type=\"hidden\" name=\"table_name[]\" value=\"$name\">\n";}
			}
		      else{echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";}

		      foreach ($field_list as $field){echo "<input type=\"hidden\" name=\"field_list[]\" value=\"$field\">\n";}

		      if (is_array($term)){foreach ($term as $sub_term){echo "<input type=\"hidden\" name=\"term[]\" value=\"$sub_term\">\n";}}
		      else {echo "<input type=\"hidden\" name=\"term\" value=\"$term\">\n";}

		      if (is_array($mode)){foreach ($mode as $sub_mode){echo "<input type=\"hidden\" name=\"mode[]\" value=\"$sub_mode\">\n";}}
		      else {echo "<input type=\"hidden\" name=\"mode\" value=\"$mode\">\n";}

		      if ($function_to_call == 'compoundTableQuery') {echo "<input type=\"hidden\" value=\"join\" value=\"$join\">\n";}

		      echo "<input type=\"hidden\" name=\"order_by\" value=\"$order_by\">\n";
		      echo "<input type=\"hidden\" name=\"last_record_retrieved\" value=\"$last_record_retrieved\">\n";
		     
                      echo "<table align=\"center\">\n";
                      echo "<tr>\n";
                      echo "<td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Deselect Selections\"></td>\n";
		      if ($records_left > $max_records_to_print_per_page)
                        {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Next $max_records_to_print_per_page Markers\"></td>\n";}
		      else
                        {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Next $records_left Markers\"></td>\n";}
                      echo "</form>\n";
                      echo "</tr>\n";

                      echo "<form action=\"individual_search.php\" name=\"skip_form2\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";
                      echo "<input type=\"hidden\" name=\"status\" value=\"$status\">\n";
                      echo "<input type=\"hidden\" name=\"individual_flag\" value=\"1\">\n";
		      echo "<input type=\"hidden\" name=\"indiv_multiple_pages\" value=\"0\">\n";
		      if (!is_array($individual_ids)) {echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$individual_ids\">\n";}
		      else
                        {
                          $indiv_id_string = join($individual_ids,',');
                          echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$indiv_id_string\">\n";
                          unset($indiv_id_string);
		        }#end else sizeof(indiv_ids) != '1'
                      echo "<input type=\"hidden\" name=\"marker_multiple_pages\" value=\"0\">\n";
                      echo "<input type=\"hidden\" name=\"marker_id\" value=\"\">\n";
                      echo "<tr>\n";
                      echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes without Phenotypes\" onClick=\"copyData('skip_form2')\"></td>\n";
                      echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Select Phenotypes\" onClick=\"copyData('skip_form2')\"></td>\n";
                      echo "</form>\n";
                      echo "</tr>\n\n";
                      echo "</table>\n";
		    }#end if more than a single page
		  else #only a single page
		    {
                      echo "<table align=\"center\">\n";
                      echo "<tr>\n";
                      echo "<td align=\"center\">&nbsp;</td>\n";
                      echo "<td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Deselect Selections\"></td>\n";
                      echo "</tr>\n";
                      echo "</table>\n";
                      echo "<br>\n";

                      echo "<table align=\"center\">\n";
                      echo "<tr>\n";
		      echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes without Phenotypes\"></td>\n";
		      echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Select Phenotypes\"></td>\n";
                      echo "</form>\n";
                      echo "</tr>\n";
                      echo "</table>\n";
		    }#end else only a single page
		  echo "<br><br>\n";

		  $ret_val = printLogOutButton('individual_search.php');
		  echo "\n\n";
		 
		 echo "<script>\n";
		 echo "function Validate(form)\n";
		 echo "$jscript\n";
		 if ($marker_multiple_pages)
                   {
                     echo "\n";
                     echo "function copyData(form_to_copy_to)\n";
                     echo "{\n";
                     echo " var marker_string = new Array();\n";
                     echo " var length = 0;\n";
                     echo " for (var i=0; i<document.form.elements['marker_id[]'].length; i++){\n";
                     echo "   if (document.form.elements['marker_id[]'][i].type == \"hidden\"){\n";
                     echo "     length = marker_string.length;\n";
                     echo "     marker_string[lenght] = document.form.elements['marker_id[]'][i].value;}\n";
                     echo "   else{\n";
                     echo "     if (document.form.elements['marker_id[]'][i].checked){\n";
                     echo "       length = marker_string.length;\n";
                     echo "       marker_string[length] = document.form.elements['marker_id[]'][i].value;}}}\n";
                     echo " if (form_to_copy_to == \"skip_form1\"){\n";
                     echo "   document.skip_form1.marker_id.value = marker_string;}\n";
                     echo " if (form_to_copy_to == \"skip_form2\"){\n";
                     echo "   document.skip_form2.marker_id.value = marker_string;}\n";
                     echo "}\n";
                   }#end if more than a single page
		 echo "</script>\n";
                 unset($marker_multiple_pages);
		}#end multiple pages of marker ids

	      #7 Select Phenotypes
	      if ((preg_match('/\w+/',$status)) and
		  (sizeof($marker_ids) > '0') and
		  ($marker_multiple_pages == '0') and
                  (!preg_match('/^\d$/',$pheno_multiple_pages)) and
		  (preg_match('/Select Phenotypes/',$submit))
		 )
                {
		 echo "Select which Phenotypes you would like data for:<br><br>\n";

		 $field_list_array = array('phenotype_id');
                 $num_of_phenos = countTableQuery('phenotype_table',$database_id,$field_list_array,'_','wildcard');
                 if (!preg_match('/^\d+$/',$num_of_phenos))
		   {
		     $date = date('Y-m-d H:i:s');
		     echo "Error #284: $date<br>\n";
		     echo "Error in call to countTableQuery from individual_search.php<br>\n";
		     echo "$num_of_phenos<br><br>\n";
		     echo "Please email the above error using The Comments/Help/Support link on the \n";
		     echo "left navigation bar.\n";
		     echo "</form>\n";
		     echo "</body></html>\n";
		     $ret_val = disconnect();
		     exit;
		   }#end if error in call to countTableQuery

		 if ($num_of_phenos == 0)
		   {
		     $date = date('Y-m-d H:i:s');
		     echo "<center>\n";
		     echo "Currently there are no phenotypes in the database.<br>\n";
		     echo "This message was generated at $date<br><br>\n";
		     echo "Continue on to get the Genotypes for the Individuals you selected by selecting the button below:<br><br>\n";

		     echo "<form action=\"individual_search.php\" name=\"all_phenotype_form\" method=\"POST\" target=\"main\">\n";
		     echo "<input type=\"hidden\" name=\"status\" value=\"$status\">\n";
                     echo "<input type=\"hidden\" name=\"individual_flag\" value=\"1\">\n";
		     echo "<input type=\"hidden\" name=\"indiv_multiple_pages\" value=\"0\">\n";
		     if (!is_array($individual_ids)) {echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$individual_ids\">\n";}
		     else
                       {
                         $indiv_id_string = join($individual_ids,',');
                         echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$indiv_id_string\">\n";
		       }#end sizeof(indiv_ids) != '1'
		     echo "<input type=\"hidden\" name=\"marker_multiple_pages\" value=\"$marker_multiple_pages\">\n";
                     if (!is_array($marker_ids)) {echo "<input type=\"hidden\" name=\"marker_id[]\" value=\"$marker_ids\">\n";}
		     else
		       {
			 $marker_id_string = join($marker_ids,',');
                         echo "<input type=\"hidden\" name=\"marker_id[]\" value=\"$marker_id_string\">\n";
		       }#end else marker ids is an array
		     echo "<input type=\"hidden\" name=\"pheno_multiple_pages\" value=\"0\">\n";
		     echo "<input type=\"submit\" name=\"submit\" value=\"Get Genotypes without Phenotypes\">\n";
		     echo "</center>\n";
		     echo "</form>\n";
                     echo "</body></html>\n";
                     $ret_val = disconnect();
                     exit;
		   }#end if no phenotypes in database

		 if ($num_of_phenos > ($max_records_to_print_per_page * 5))
		   {
                     echo "<hr>\n";
                     echo "<br>\n";
		     echo "There are <b>$num_of_phenos</b> phenotypes in the database.<br>\n";
                     echo "If you would like to get phenotype values for all of these phenotypes for the individuals you selected, \n";
                     echo "without selecting each phenotype, please click the \n";
                     echo "button below.<br><br>\n";

                     $phenotype_id_array = distinctTableQuery('phenotype_id','phenotype_table',$database_id,$field_list_array,'_','wildcard','all','phenotype_name');
		     if (!is_array($phenotype_id_array))
                       {
		         $date = date('Y-m-d H:i:s');
		         echo "Error #285: $date<br>\n";
		         echo "Error in call to distinctTableQuery from individual_search.php<br>\n";
		         echo "$phenotype_id_array<br><br>\n";
		         echo "Please email the above error using The Comments/Help/Support link on the \n";
		         echo "left navigation bar.\n";
		         echo "</form>\n";
		         echo "</body></html>\n";
		         $ret_val = disconnect();
		         exit;
		       }#end if (!is_array(phenotype_id_array))
                     $phenotype_id_string = join($phenotype_id_array,',');
                     unset($phenotype_id_array);

                     echo "<form action=\"individual_search.php\" name=\"all_phenotype_form\" method=\"POST\" target=\"main\">\n";
                     echo "<input type=\"hidden\" name=\"status\" value=\"$status\">\n";
                     echo "<input type=\"hidden\" name=\"individual_flag\" value=\"1\">\n";
		     echo "<input type=\"hidden\" name=\"indiv_multiple_pages\" value=\"0\">\n";
		     if (!is_array($individual_ids)) {echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$individual_ids\">\n";}
		     else
                       {
                         $indiv_id_string = join($individual_ids,',');
                         echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$indiv_id_string\">\n";
		       }#end sizeof(indiv_ids) != '1'
		     echo "<input type=\"hidden\" name=\"marker_multiple_pages\" value=\"$marker_multiple_pages\">\n";
                     if (!is_array($marker_ids)) {echo "<input type=\"hidden\" name=\"marker_id[]\" value=\"$marker_ids\">\n";}
		     else
		       {
			 $marker_id_string = join($marker_ids,',');
                         echo "<input type=\"hidden\" name=\"marker_id[]\" value=\"$marker_id_string\">\n";
		       }#end else marker ids is an array
		     echo "<input type=\"hidden\" name=\"pheno_multiple_pages\" value=\"0\">\n";
		     echo "<input type=\"hidden\" name=\"pheno_id[]\" value=\"$phenotype_id_string\">\n";
                     echo "<center>\n";
		     echo "<input type=\"submit\" name=\"submit\" value=\"Get All Genotypes & Phenotypes\">\n";
		     echo "</center>\n";
                     echo "</form>\n";
                     echo "<br>\n";
                     echo "<hr>\n";
                     echo "<br><br><br>\n";
                     echo "Otherwise, continue below to select the phenotypes you would like information for.<br><br>\n";
                   }#end if too many phenotypes to be efficiently displayed and chosen of the web

		 if ($num_of_phenos > $max_records_to_print_per_page)
		   {
                     $pheno_multiple_pages = 1;
		     $from                 = "0";
                     $to                   = $max_records_to_print_per_page - 1;
                     $range                = "$from"."-"."$to";
		     $pheno_rec_list = tableQuery('phenotype_table',$database_id,$field_list_array,'_','wildcard',$range,'phenotype_name');
		     if (!is_array($pheno_rec_list))
		       {
			 $date = date('Y-m-d H:i:s');
			 echo "Error #286: $date<br>\n";
			 echo "Error in call to tableQuery from individual_search.php<br>\n";
			 echo "$pheno_rec_list<br><br>\n";
			 echo "Please email the above error using The Comments/Help/Support link on the \n";
			 echo "left navigation bar.\n";
			 echo "</form>\n";
			 echo "</body></html>\n";
			 $ret_val = disconnect();
			 exit;
		       }#end if (!is_array(pheno_rec_list))
		     if (sizeof($pheno_rec_list) == 0)
		       {
			 $date = date('Y-m-d H:i:s');
			 echo "<b>Currently, there are no phenotypess in the database</b>.<br>\n";
			 echo "Therefore there are no values for the individuals you selected.<br>\n";
			 echo "This message was generated at $date<br>\n";
			 echo "</body></html>\n";
			 $ret_val = disconnect();
			 exit;
		       }
		     $final_function_call   = 'tableQuery';
                     $final_table_name      = 'phenotype_table';
                     $final_field_list      = $field_list_array;
                     $final_term            = '_';
                     $final_mode            = 'wildcard';
                     $final_order_by        = 'phenotype_name';
                     $last_record_retrieved = $max_records_to_print_per_page;
		   }#end if more than a single page
		 else #only a single page
		   {
                     $pheno_multiple_pages = 0;
                     $range                = "all";
		     $pheno_rec_list = tableQuery('phenotype_table',$database_id,$field_list_array,'_','wildcard',$range,'phenotype_name');
		     if (!is_array($pheno_rec_list))
		       {
			 $date = date('Y-m-d H:i:s');
			 echo "Error #287: $date<br>\n";
			 echo "Error in call to tableQuery from individual_search.php<br>\n";
			 echo "$pheno_rec_list<br><br>\n";
			 echo "Please email the above error using The Comments/Help/Support link on the \n";
			 echo "left navigation bar.\n";
			 echo "</form>\n";
			 echo "</body></html>\n";
			 $ret_val = disconnect();
			 exit;
		       }#end if (!is_array(pheno_rec_list))
		     if (sizeof($pheno_rec_list) == 0)
		       {
			 $date = date('Y-m-d H:i:s');
			 echo "<b>Currently, there are no phenotypes in the database</b>.<br>\n";
			 echo "Therefore there are no values for the individuals you selected.<br>\n";
			 echo "This message was generated at $date<br>\n";
			 echo "</body></html>\n";
			 $ret_val = disconnect();
			 exit;
		       }
		   }#end else only a single page

                 $ret_val = printLogOutButton('individual_search.php');
                 echo "<br><br>\n\n";

                 if ($pheno_multiple_pages)#more than one page of phenotypes
                   {
                     echo "<table align=\"center\">\n";
                     echo "<form action=\"individual_search.php\" name=\"skip_form1\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";
                     echo "<input type=\"hidden\" name=\"status\" value=\"$status\">\n";
                     echo "<input type=\"hidden\" name=\"individual_flag\" value=\"1\">\n";
                     echo "<input type=\"hidden\" name=\"indiv_multiple_pages\" value=\"$indiv_multiple_pages\">\n";
		     if (!is_array($individual_ids)) {echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$individual_ids\">\n";}
		     else #more than one indiv_id or not comma-sep list
                       {
                         $indiv_id_string = join($individual_ids,',');
                         echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$indiv_id_string\">\n";
                         unset($indiv_id_string);
		       }#end else more than one indiv_id

                     echo "<input type=\"hidden\" name=\"marker_multiple_pages\" value=\"$marker_multiple_pages\">\n";
		     if (!is_array($marker_ids)) {echo "<input type=\"hidden\" name=\"marker_id[]\" value=\"$marker_ids\">\n";}
		     else #more than one marker_ids
                       {
                         $marker_id_string = join($marker_ids,',');
                         echo "<input type=\"hidden\" name=\"marker_id[]\" value=\"$marker_id_string\">\n";
                         unset($marker_id_string);
		       }#end else more than one marker_id
                     echo "<input type=\"hidden\" name=\"pheno_multiple_pages\" value=\"0\">\n";
                     echo "<input type=\"hidden\" name=\"pheno_id\" value=\"\">\n";
                     echo "<tr>\n";
                     echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes and Phenotypes\" onClick=\"copyData('skip_form1')\"></td>\n";
                     echo "</form>\n\n";

                     echo "<form action=\"individual_search.php\" name=\"form\" method=\"POST\" target=\"main\">\n";
                     $num_records_left = ($num_of_phenos - $last_record_retrieved);
                     if ($num_records_left > $max_records_to_print_per_page)
                       {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Next $max_records_to_print_per_page Phenotypes\"></td>\n";}
                     else
                       {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Next $num_records_left Phenotypes\"></td>\n";}
                     echo "</tr>\n";
                     echo "</table>\n\n";
                     echo "<br>\n";

                     echo "<table align=\"center\">\n";
                     echo "<tr>\n";
                     echo "<td align=\"center\">&nbsp;</td>\n";
                     echo "<td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Reset Values\"></td>\n";
                     echo "</tr>\n";
                     echo "</table>\n\n";
                   }#end if more than one page of phenotypes
                 else #only one page of phenotypes
                   {
                     echo "<table align=\"center\">\n";
                     echo "<form action=\"individual_search.php\" name=\"form\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(this))\">\n";
                     echo "<tr>\n";
                     echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes and Phenotypes\"></td>\n";
                     echo "<td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Reset Values\"></td>\n";
                     echo "</tr>\n";
                     echo "</table>\n";
                   }#end only one page of phenotypes
		 echo "<br><br>\n\n";

		 $jscript = printPhenotypeCheckList($pheno_rec_list);
		 if ($jscript == '0')
                   {
		     $date = date('Y-m-d H:i:s');
		    echo "Error #288: $date<br>\n";
		    echo "Error in call to printPhenotypeCheckList from individual_search.php<br>\n";
		    echo "See above error message from printPhenotypeCheckList for an explanation.<br><br>\n";
		    echo "Please email the above error using The Comments/Help/Support link on the \n";
		    echo "left navigation bar.\n";
		    echo "</form>\n";
		    echo "</body></html>\n";
		    $ret_val = disconnect();
		    exit;
		   }#end if (jscript == '0')
                 echo "<br><br>\n\n";

                 echo "<input type=\"hidden\" name=\"status\" value=\"$status\">\n";
                 echo "<input type=\"hidden\" name=\"individual_flag\" value=\"1\">\n";
                 echo "<input type=\"hidden\" name=\"indiv_multiple_pages\" value=\"$indiv_multiple_pages\">\n";
		 if (!is_array($individual_ids)) {echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$individual_ids\">\n";}
		 else #more than one indiv_id or not comma-sep list
                   {
                    $indiv_id_string = join($individual_ids,',');
                    echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$indiv_id_string\">\n";
		   }#end else more than one indiv_id

                 echo "<input type=\"hidden\" name=\"marker_multiple_pages\" value=\"$marker_multiple_pages\">\n";
		 if (!is_array($marker_ids)) {echo "<input type=\"hidden\" name=\"marker_id[]\" value=\"$marker_ids\">\n";}
		 else #more than one marker_ids
                   {
                    $marker_id_string = join($marker_ids,',');
                    echo "<input type=\"hidden\" name=\"marker_id[]\" value=\"$marker_id_string\">\n";
		   }#end else more than one marker_id

                 echo "<input type=\"hidden\" name=\"pheno_multiple_pages\" value=\"$pheno_multiple_pages\">\n";
                 if ($pheno_multiple_pages)
                   {
                     echo "<input type=\"hidden\" name=\"function_to_call\" value=\"$final_function_call\">\n";
		     if ($final_function_call == 'tableJoin') 
		       {
			 foreach ($final_table_name as $name) {echo "<input type=\"hidden\" name=\"table_name[]\" value=\"$name\">\n";}
		       }
		     else{echo "<input type=\"hidden\" name=\"table_name\" value=\"$final_table_name\">\n";}

		     foreach ($final_field_list as $field){echo "<input type=\"hidden\" name=\"field_list[]\" value=\"$field\">\n";}

		     if (is_array($final_term)){foreach ($final_term as $term){echo "<input type=\"hidden\" name=\"term[]\" value=\"$term\">\n";}}
		     else {echo "<input type=\"hidden\" name=\"term\" value=\"$final_term\">\n";}

		     if (is_array($final_mode)){foreach ($final_mode as $mode){echo "<input type=\"hidden\" name=\"mode[]\" value=\"$mode\">\n";}}
		     else {echo "<input type=\"hidden\" name=\"mode\" value=\"$final_mode\">\n";}

		     if ($final_function_call == 'compoundTableQuery') {echo "<input type=\"hidden\" value=\"join\" value=\"$final_join\">\n";}

		     echo "<input type=\"hidden\" name=\"order_by\" value=\"$final_order_by\">\n";
		     echo "<input type=\"hidden\" name=\"last_record_retrieved\" value=\"$last_record_retrieved\">\n";

                     echo "<table align=\"center\">\n";
                     echo "<tr>\n";
                     echo "<td align=\"center\">&nbsp;</td>\n";
                     echo "<td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Reset Values\"></td>\n";
                     echo "</tr>\n";
                     echo "</table>\n\n";
                     echo "<br>\n";

                     echo "<table align=\"center\">\n";
                     echo "<tr>\n";
                     if ($num_records_left > $max_records_to_print_per_page)
                       {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Next $max_records_to_print_per_page Phenotypes\"></td>\n";}
                     else
                       {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Next $num_records_left Phenotypes\"></td>\n";}
                     echo "</form>\n\n";

                     echo "<form action=\"individual_search.php\" name=\"skip_form2\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";
                     echo "<input type=\"hidden\" name=\"status\" value=\"$status\">\n";
                     echo "<input type=\"hidden\" name=\"individual_flag\" value=\"1\">\n";
                     echo "<input type=\"hidden\" name=\"indiv_multiple_pages\" value=\"$indiv_multiple_pages\">\n";
		     if (!is_array($individual_ids)) {echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$individual_ids\">\n";}
		     else #more than one indiv_id or not comma-sep list
                       {
                         $indiv_id_string = join($individual_ids,',');
                         echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$indiv_id_string\">\n";
                         unset($indiv_id_string);
		       }#end else more than one indiv_id

                     echo "<input type=\"hidden\" name=\"marker_multiple_pages\" value=\"$marker_multiple_pages\">\n";
		     if (!is_array($marker_ids)) {echo "<input type=\"hidden\" name=\"marker_id[]\" value=\"$marker_ids\">\n";}
		     else #more than one marker_ids
                       {
                         $marker_id_string = join($marker_ids,',');
                         echo "<input type=\"hidden\" name=\"marker_id[]\" value=\"$marker_id_string\">\n";
                         unset($marker_id_string);
		       }#end else more than one marker_id
                     echo "<input type=\"hidden\" name=\"pheno_multiple_pages\" value=\"0\">\n";
                     echo "<input type=\"hidden\" name=\"pheno_id\" value=\"\">\n";
                     echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes and Phenotypes\" onClick=\"copyData('skip_form2')\"></td>\n";
                     echo "</form>\n";
                     echo "</table>\n";
                   }#end multiple pages of phenotypes
                 else #only one page of phenotypes
                   {
                     echo "<table align=\"center\">\n";
                     echo "<tr>\n";
                     echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes and Phenotypes\"></td>\n";
                     echo "<td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Reset Values\"></td>\n";
                     echo "</form>\n";
                     echo "</tr>\n";
                     echo "</table>\n";
                   }
		 echo "<br><br>\n\n";

                 $ret_val = printLogOutButton('individual_search.php');
		 echo "\n\n";
		 
		 echo "<script>\n";
		 echo "function Validate(form)\n";
		 echo "$jscript\n";
                 if ($pheno_multiple_pages)
                   {
                     echo "\n";
                     echo "function copyData(form_to_copy_to)\n";
                     echo "{\n";
                     echo " var pheno_string = new Array();\n";
                     echo " var length = 0;\n";
                     echo " for (var i=0; i<document.form.elements['pheno_id[]'].length; i++){\n";
                     echo "   if (document.form.elements['pheno_id[]'][i].checked){\n";
                     echo "     length = pheno_string.length;\n";
                     echo "     pheno_string[length] = document.form.elements['pheno_id[]'][i].value;}}\n";
                     echo " if (form_to_copy_to == \"skip_form1\"){\n";
                     echo "   document.skip_form1.pheno_id.value = pheno_string;}\n";
                     echo " if (form_to_copy_to == \"skip_form2\"){\n";
                     echo "   document.skip_form2.pheno_id.value = pheno_string;}\n";
                     echo "}\n";
                   }#end if more than a single page
		 echo "</script>\n";
                 unset($pheno_multiple_pages);
	        }#end if ((preg_match('/\w+/',status)) and
		 #     (sizeof(marker_ids) > '0') and
		 #     (submit == 'Select Phenotypes')
		 #    )

              if ((preg_match('/\w+/',$status)) and
                  (sizeof($marker_ids) > '0') and
                  ($marker_multiple_pages == '0') and
                  ($pheno_multiple_pages == '1')
                 )
                {
                  echo "Please select the Phenotypes you want data for:<br><br>\n";

		  if ($function_to_call == 'tableQuery')
		    {
		      $num_of_phenos = countTableQuery($table_name,$database_id,$field_list,$term,$mode);
		      if (!preg_match('/^\d+$/',$num_of_phenos))
			{
			  $date = date('Y-m-d H:i:s');
			  echo "Error #289: $date<br>\n";
			  echo "Error in call to countTableQuery from individual_search.php<br>\n";
			  echo "$num_of_phenos<br><br>\n";
			  echo "Please email the above error using The Comments/Help/Support link on the \n";
			  echo "left navigation bar.\n";
			  echo "</form>\n";
			  echo "</body></html>\n";
			  $ret_val = disconnect();
			  exit;
			}#end error in call to countTableQuery
		      $records_yet_to_be_retrieved = $num_of_phenos - $last_record_retrieved;

		      if ($records_yet_to_be_retrieved > $max_records_to_print_per_page)
			{
                          $pheno_multiple_pages = 1;
			  $from = $last_record_retrieved;
			  $to   = ($last_record_retrieved-1) + $max_records_to_print_per_page;
			  $range = "$from"."-"."$to";
			  $pheno_rec_list = tableQuery($table_name,$database_id,$field_list,$term,$mode,$range,$order_by);
			  if (!is_array($pheno_rec_list))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #290: $date<br>\n";
			      echo "Error in call to tableQuery from individual_search.php<br>\n";
			      echo "$pheno_rec_list<br><br>\n";
			      echo "Please email the above error using The Comments/Help/Support link on the \n";
			      echo "left navigation bar.\n";
			      echo "</form>\n";
			      echo "</body></html>\n";
			      $ret_val = disconnect();
			      exit;
			    }#end if (!is_array(pheno_rec_list))
			  if (sizeof($pheno_rec_list) == 0)
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #291: $date<br>\n";
			      echo "Error in call to individual_search.php<br>\n";
			      echo "There should be records returned for tableQuery search with parameters:<br>\n";
			      echo "table_name = $table_name<br>\n";
			      echo "field_list = ".join(',',$field_list)."<br>\n";
			      echo "term       = $term<br>\n";
			      echo "mode       = $mode<br>\n";
			      echo "range      = $range<br>\n";
			      echo "order_by   = $order_by<br>\n";
			      echo "But no records were returned<br><br>\n";
			      echo "Please email the above error using The Comments/Help/Support link on the \n";
			      echo "left navigation bar.\n";
			      echo "</form>\n";
			      echo "</body></html>\n";
			      $ret_val = disconnect();
			      exit;
			    }#end if no records returned
                          $last_record_retrieved = $to + 1;
			}#end if more than a single page
		      else #only a single page
			{
                          $pheno_multiple_pages = 0;
			  $from = $last_record_retrieved;
			  $to   = $num_of_phenos - 1;
			  $range = "$from"."-"."$to";
			  $pheno_rec_list = tableQuery($table_name,$database_id,$field_list,$term,$mode,$range,$order_by);
			  if (!is_array($pheno_rec_list))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #292: $date<br>\n";
			      echo "Error in call to tableQuery from individual_search.php<br>\n";
			      echo "$pheno_rec_list<br><br>\n";
			      echo "Please email the above error using The Comments/Help/Support link on the \n";
			      echo "left navigation bar.\n";
			      echo "</form>\n";
			      echo "</body></html>\n";
			      $ret_val = disconnect();
			      exit;
			    }#end if (!is_array(pheno_rec_list))
			  if (sizeof($pheno_rec_list) == 0)
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #293: $date<br>\n";
			      echo "Error in call to individual_search.php<br>\n";
			      echo "There should be records returned for tableQuery search with parameters:<br>\n";
			      echo "table_name = $table_name<br>\n";
			      echo "field_list = ".join(',',$field_list)."<br>\n";
			      echo "term       = $term<br>\n";
			      echo "mode       = $mode<br>\n";
			      echo "range      = $range<br>\n";
			      echo "order_by   = $order_by<br>\n";
			      echo "But no records were returned<br><br>\n";
			      echo "Please email the above error using The Comments/Help/Support link on the \n";
			      echo "left navigation bar.\n";
			      echo "</form>\n";
			      echo "</body></html>\n";
			      $ret_val = disconnect();
			      exit;
			    }#end if no records returned
		        }#end else only a single page
		    }#end if tableQuery

		  $ret_val = printLogOutButton('individual_search.php');
                  echo "<br><br>\n";

		  if ($pheno_multiple_pages) 
		    {
                      echo "<table align=\"center\">\n";
                      echo "<form action=\"individual_search.php\" name=\"skip_form1\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";
                      echo "<input type=\"hidden\" name=\"status\" value=\"$status\">\n";
                      echo "<input type=\"hidden\" name=\"individual_flag\" value=\"1\">\n";
		      echo "<input type=\"hidden\" name=\"indiv_multiple_pages\" value=\"0\">\n";
		      if (!is_array($individual_ids)) {echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$individual_ids\">\n";}
		      else
                        {
                          $indiv_id_string = join($individual_ids,',');
                          echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$indiv_id_string\">\n";
                          unset($indiv_id_string);
		        }#end else sizeof(indiv_ids) != '1'

		      echo "<input type=\"hidden\" name=\"marker_multiple_pages\" value=\"$marker_multiple_pages\">\n";
		      if (!is_array($marker_ids)) {echo "<input type=\"hidden\" name=\"marker_id[]\" value=\"$marker_ids\">\n";}
		      else
		        {
                          $marker_id_string = join($marker_ids,',');
                          echo "<input type=\"hidden\" name=\"marker_id[]\" value=\"$marker_id_string\">\n";
                          unset($marker_id_string);
		        }#end else marker ids is an array
                      echo "<input type=\"hidden\" name=\"pheno_multiple_pages\" value=\"0\">\n";
                      echo "<input type=\"hidden\" name=\"pheno_id\" value=\"\">\n";
                      echo "<tr>\n";
                      echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes and Phenotypes\" onClick=\"copyData('skip_form1')\"></td>\n";
                      echo "</form>\n\n";

		      echo "<form action=\"individual_search.php\" name=\"form\" method=\"POST\" target=\"main\">\n";
		      $records_left = ($num_of_phenos - $last_record_retrieved );
		      if ($records_left > $max_records_to_print_per_page) 
                        {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Next $max_records_to_print_per_page Phenotypes\"></td>\n";}
		      else
                        {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Next $records_left Phenotypes\"></td>\n";}
                      echo "</tr>\n";
                      echo "</table>\n";
                      echo "<br>\n";
                      echo "<table align=\"center\">\n";
                      echo "<tr>\n";
                      echo "<td align=\"center\">&nbsp;</td>\n";
		      echo "<td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Deselect Selections\"></td>\n";
                      echo "</tr>\n";
                      echo "</table>\n";
		    }#end multiple pages
		  else #only one page
		    {
                      echo "<table align=\"center\">\n";
		      echo "<form action=\"individual_search.php\" name=\"form\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(this))\">\n";
                      echo "<tr>\n";
		      echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes & Phenotypes\"></td>\n";
                      echo "<td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Deselect Selections\"></td>\n";
                      echo "</tr>\n";
                      echo "</table>\n";
		    }#end only one page of phenotypes
                  echo "<br><br>\n\n";

		  $jscript = printPhenotypeCheckList($pheno_rec_list);
		  if ($jscript == '0')
                    {
		      $date = date('Y-m-d H:i:s');
		      echo "Error #294: $date<br>\n";
		      echo "Error in call to printPhenotypeCheckList from individual_search.php<br>\n";
		      echo "See above error message from printPhenotypeCheckList for an explanation.<br><br>\n";
		      echo "Please email the above error using The Comments/Help/Support link on the \n";
		      echo "left navigation bar. \n";
		      echo "</form>\n";
		      echo "</body></html>\n";
		      $ret_val = disconnect();
		      exit;
		    }#end if (jscript == '0')
                  echo "<br><br>\n";

                  echo "<input type=\"hidden\" name=\"status\" value=\"$status\">\n";
                  echo "<input type=\"hidden\" name=\"individual_flag\" value=\"1\">\n";
		  echo "<input type=\"hidden\" name=\"indiv_multiple_pages\" value=\"0\">\n";
		  if (!is_array($individual_ids)) {echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$individual_ids\">\n";}
		  else
                    {
                      $indiv_id_string = join($individual_ids,',');
                      echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$indiv_id_string\">\n";
                      unset($indiv_id_string);
		    }#end else sizeof(indiv_ids) != '1'

		  echo "<input type=\"hidden\" name=\"marker_multiple_pages\" value=\"$marker_multiple_pages\">\n";
		  if (!is_array($marker_ids)) {echo "<input type=\"hidden\" name=\"marker_id[]\" value=\"$marker_ids\">\n";}
		  else
		    {
                      $marker_id_string = join($marker_ids,',');
                      echo "<input type=\"hidden\" name=\"marker_id[]\" value=\"$marker_id_string\">\n";
                      unset($marker_id_string);
		    }#end else marker ids is an array

		  echo "<input type=\"hidden\" name=\"pheno_multiple_pages\" value=\"$pheno_multiple_pages\">\n";
                  if (sizeof($pheno_ids) > 0)
                    {
                      if (!is_array($pheno_ids)) {echo "<input type=\"hidden\" name=\"pheno_id[]\" value=\"$pheno_ids\">\n";}
                      else
                        {
                          $pheno_id_string = join($pheno_ids,',');
                          echo "<input type=\"hidden\" name=\"pheno_id[]\" value=\"$pheno_id_string\">\n";
                          unset($pheno_id_string);
                        }
                    }#end if have pheno ids from previous page(s)

		  if ($pheno_multiple_pages)
		    {
		      echo "<input type=\"hidden\" name=\"function_to_call\" value=\"$function_to_call\">\n";
		      if ($final_function_call == 'tableJoin') 
			{
			  foreach ($final_table_name as $name) {echo "<input type=\"hidden\" name=\"table_name[]\" value=\"$name\">\n";}
			}
		      else{echo "<input type=\"hidden\" name=\"table_name\" value=\"$final_table_name\">\n";}

		      foreach ($final_field_list as $field){echo "<input type=\"hidden\" name=\"field_list[]\" value=\"$field\">\n";}

		      if (is_array($final_term)){foreach ($final_term as $term){echo "<input type=\"hidden\" name=\"term[]\" value=\"$term\">\n";}}
		      else {echo "<input type=\"hidden\" name=\"term\" value=\"$final_term\">\n";}

		      if (is_array($final_mode)){foreach ($final_mode as $mode){echo "<input type=\"hidden\" name=\"mode[]\" value=\"$mode\">\n";}}
		      else {echo "<input type=\"hidden\" name=\"mode\" value=\"$final_mode\">\n";}

		      if ($final_function_call == 'compoundTableQuery') {echo "<input type=\"hidden\" value=\"join\" value=\"$final_join\">\n";}

		      echo "<input type=\"hidden\" name=\"order_by\" value=\"$final_order_by\">\n";
		      echo "<input type=\"hidden\" name=\"last_record_retrieved\" value=\"$last_record_retrieved\">\n";
		     
                      echo "<table align=\"center\">\n";
                      echo "<tr>\n";
                      echo "<td align=\"center\">&nbsp;</td>\n";
                      echo "<td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Deselect Selections\"></td>\n";
                      echo "</tr>\n";
                      echo "</table>\n";
                      echo "<br>\n";
                      echo "<table align=\"center\">\n";
                      echo "<tr>\n";
		      if ($records_left > $max_records_to_print_per_page)
                        {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Next $max_records_to_print_per_page Phenotypes\"></td>\n";}
		      else
                        {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Next $records_left Phenotypes\"></td>\n";}
                      echo "</form>\n\n";

                      echo "<form action=\"individual_search.php\" name=\"skip_form2\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";
                      echo "<input type=\"hidden\" name=\"status\" value=\"$status\">\n";
                      echo "<input type=\"hidden\" name=\"individual_flag\" value=\"1\">\n";
		      echo "<input type=\"hidden\" name=\"indiv_multiple_pages\" value=\"0\">\n";
		      if (!is_array($individual_ids)) {echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$individual_ids\">\n";}
		      else
                        {
                          $indiv_id_string = join($individual_ids,',');
                          echo "<input type=\"hidden\" name=\"indiv_id[]\" value=\"$indiv_id_string\">\n";
                          unset($indiv_id_string);
		        }#end else sizeof(indiv_ids) != '1'

		      echo "<input type=\"hidden\" name=\"marker_multiple_pages\" value=\"$marker_multiple_pages\">\n";
		      if (!is_array($marker_ids)) {echo "<input type=\"hidden\" name=\"marker_id[]\" value=\"$marker_ids\">\n";}
		      else
		        {
                          $marker_id_string = join($marker_ids,',');
                          echo "<input type=\"hidden\" name=\"marker_id[]\" value=\"$marker_id_string\">\n";
                          unset($marker_id_string);
		        }#end else marker ids is an array
                      echo "<input type=\"hidden\" name=\"pheno_multiple_pages\" value=\"0\">\n";
                      echo "<input type=\"hidden\" name=\"pheno_id\" value=\"\">\n";
                      echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes and Phenotypes\" onClick=\"copyData('skip_form2')\"></td>\n";
                      echo "</form>\n";
                      echo "</tr>\n";
                      echo "</table>\n";
		    }#end have multiple pages to display
		  else #only have one page of phenotypes to display
		    {
                      echo "<table align=\"center\">\n";
                      echo "<tr>\n";
		      echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes & Phenotypes\"></td>\n";
                      echo "<td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Deselect Selections\"></td>\n";
                      echo "</form>\n";
                      echo "</tr>\n";
                      echo "</table>\n";
		    }
		  echo "<br><br>\n";

                  $ret_val = printLogOutButton('individual_search.php');
		  echo "</form>\n\n";
		 
		  echo "<script>\n";
		  echo "function Validate(form)\n";
		  echo "$jscript\n";
		  if ($pheno_multiple_pages)
                    {
                      echo "\n";
                      echo "function copyData(form_to_copy_to)\n";
                      echo "{\n";
                      echo " var pheno_string = new Array();\n";
                      echo " var length = 0;\n";
                      echo " for (var i=0; i<document.form.elements['pheno_id[]'].length; i++){\n";
                      echo "   if (document.form.elements['pheno_id[]'][i].type == \"hidden\"){\n";
                      echo "     length = pheno_string.length;\n";
                      echo "     pheno_string[length] = document.form.elements['pheno_id[]'][i].value;}\n";
                      echo "   else{\n";
                      echo "     if (document.form.elements['pheno_id[]'][i].checked){\n";
                      echo "       length = pheno_string.length;\n";
                      echo "       pheno_string[length] = document.form.elements['pheno_id[]'][i].value;}}}\n";
                      echo " if (form_to_copy_to == \"skip_form1\"){\n";
                      echo "   document.skip_form1.pheno_id.value = pheno_string;}\n";
                      echo " if (form_to_copy_to == \"skip_form2\"){\n";
                      echo "   document.skip_form2.pheno_id.value = pheno_string;}\n";
                      echo "}\n";
                    }#end if more than a single page
		  echo "</script>\n";
                  unset($pheno_multiple_pages);
                }#end if have status,marker_ids,indiv_ids,but NOT all phenotypes

              #Have all the information, but haven't selected wheter want analysis files
              if (
		  (
		   (preg_match('/\w+/',$status)) and
		   (sizeof($marker_ids) > '0') and
                   ($marker_multiple_pages == '0') and
		   (preg_match('/without Phenotypes/',$submit)) and
                   (!preg_match('/\d/',$create_analysis_files))
		  ) or
                  (
		   (preg_match('/\w+/',$status)) and
		   (sizeof($marker_ids) > '0') and
		   ($marker_multiple_pages == '0') and
		   (sizeof($pheno_ids) > '0') and
                   ($pheno_multiple_pages == '0') and
                   (!preg_match('/\d/',$create_analysis_files))
		  )
                 )
                {
                  echo "<form action=\"individual_search.php\" name=\"form\" method=\"POST\" target=\"main\">\n";
                  echo "Please select whether you would like to generate input files for an analysis program using Mega2:<br><br>\n";

                  echo "<table align=\"center\">\n";
                  echo "<tr><td>Do NOT Generate Analysis Files:</td><td><input type=\"radio\" name=\"create_analysis_files\" value=\"0\" checked></td><td>(Downloaded in preMakeped Format)</td></tr>\n";
                  echo "<tr><td>Generate Analysis Files:</td><td><input type=\"radio\" name=\"create_analysis_files\" value=\"1\"></td></tr>\n";
                  echo "</table>\n";
                  echo "<br><br>\n";

                  echo "<input type=\"hidden\" name=\"individual_flag\" value=\"$individual_flag\">\n";
                  echo "<input type=\"hidden\" name=\"status\" value=\"$status\">\n";
                  echo "<input type=\"hidden\" name=\"indiv_multiple_pages\" value=\"$indiv_multiple_pages\">\n";
                  if (is_array($individual_ids))
                    {
                      $term = join($individual_ids,',');
                      echo "<input type=\"hidden\" name=\"indiv_id\" value=\"$term\">\n";
                      unset($term);
                    }
                  else {echo "<input type=\"hidden\" name=\"indiv_id\" value=\"$individual_ids\">\n";}
                  echo "<input type=\"hidden\" name=\"marker_multiple_pages\" value=\"$marker_multiple_pages\">\n";
                  if (is_array($marker_ids))
                    {
                      $term = join($marker_ids,',');
                      echo "<input type=\"hidden\" name=\"marker_id\" value=\"$term\">\n";
                      unset($term);
                    }
                  else {echo "<input type=\"hidden\" name=\"marker_id\" value=\"$marker_ids\">\n";}
                  if (preg_match('/\d/',$pheno_multiple_pages))
                    {
                      echo "<input type=\"hidden\" name=\"pheno_multiple_pages\" value=\"$pheno_multiple_pages\">\n";
                      if (is_array($pheno_ids))
                        {
                          $term = join($pheno_ids,',');
                          echo "<input type=\"hidden\" name=\"pheno_id\" value=\"$term\">\n";
                          unset($term);
                        }
                      else {echo "<input type=\"hidden\" name=\"pheno_id\" value=\"$pheno_ids\">\n";}
                    }#end if have phenotypes

                  echo "<table align=\"center\">\n";
                  echo "<tr>\n";
                  echo "<td><input type=\"submit\" name=\"submit\" value=\"Get Data\"></td>\n";
                  echo "<td><input type=\"reset\" name=\"reset\" value=\"Reset Selection\"></td>\n";
                  echo "</table>\n";
                  echo "</form>\n";
                  echo "<br><br>\n\n";

                  printLogOutButton('individual_search.php');
                }#end if Have all the information, but haven't selected wheter want analysis files

              #Want analysis files, but haven't selected which analyses
              if (
                  (
		   (preg_match('/\w+/',$status)) and
		   (sizeof($marker_ids) > '0') and
                   ($marker_multiple_pages == '0') and
                   (!preg_match('/\d/',$pheno_multiple_pages)) and
                   ($create_analysis_files == '1') and
                   (!preg_match('/\d+/',$analysis_option))
		  ) or
                  (
		   (preg_match('/\w+/',$status)) and
		   (sizeof($marker_ids) > '0') and
		   ($marker_multiple_pages == '0') and
		   (sizeof($pheno_ids) > '0') and
                   ($pheno_multiple_pages == '0') and
                   ($create_analysis_files == '1') and
                   (!preg_match('/\d+/',$analysis_option))
		  )
                 )
                {
                  echo "<form action=\"individual_search.php\" name=\"form\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(this))\" onReset=\"resetSubMenu()\">\n";
                  $jscript = printMega2Form();
                  if ($jscript == '0')
                    {
                      $date = date('Y-m-d H:i:s');
                      echo "Error #295: $date<br><br>\n";
                      echo "Error in call to printMega2Form from individual_search.php<br>\n";
                      echo "Please see above error message from printMega2Form for an explanation.<br><br>\n";
                      echo "Please email the above error using Comments/Help/Support link \n";
                      echo "in the left navigation bar.<br>\n";
                      echo "</body></html>\n";
                      $ret_val = disconnect();
                      exit;
                    }#end if error in call to printMega2Form
                  echo "<br><br>\n";

                  echo "<input type=\"hidden\" name=\"create_analysis_files\" value=\"$create_analysis_files\">\n";
                  echo "<input type=\"hidden\" name=\"individual_flag\" value=\"$individual_flag\">\n";
                  echo "<input type=\"hidden\" name=\"status\" value=\"$status\">\n";
                  echo "<input type=\"hidden\" name=\"indiv_multiple_pages\" value=\"$indiv_multiple_pages\">\n";
                  if (is_array($individual_ids))
                    {
                      $term = join($individual_ids,',');
                      echo "<input type=\"hidden\" name=\"indiv_id\" value=\"$term\">\n";
                      unset($term);
                    }
                  else {echo "<input type=\"hidden\" name=\"indiv_id\" value=\"$individual_ids\">\n";}
                  echo "<input type=\"hidden\" name=\"marker_multiple_pages\" value=\"$marker_multiple_pages\">\n";
                  if (is_array($marker_ids))
                    {
                      $term = join($marker_ids,',');
                      echo "<input type=\"hidden\" name=\"marker_id\" value=\"$term\">\n";
                      unset($term);
                    }
                  else {echo "<input type=\"hidden\" name=\"marker_id\" value=\"$marker_ids\">\n";}
                  if (preg_match('/\d/',$pheno_multiple_pages))
                    {
                      echo "<input type=\"hidden\" name=\"pheno_multiple_pages\" value=\"$pheno_multiple_pages\">\n";
                      if (is_array($pheno_ids))
                        {
                          $term = join($pheno_ids,',');
                          echo "<input type=\"hidden\" name=\"pheno_id\" value=\"$term\">\n";
                          unset($term);
                        }
                      else {echo "<input type=\"hidden\" name=\"pheno_id\" value=\"$pheno_ids\">\n";}
                    }#end if have phenotypes

                  echo "<table align=\"center\">\n";
                  echo "<tr>\n";
                  echo "<td><input type=\"submit\" name=\"submit\" value=\"Get Data\"></td>\n";
                  echo "<td><input type=\"reset\" name=\"reset\" value=\"Reset Selection\"></td>\n";
                  echo "</table>\n";
                  echo "</form>\n";
                  echo "<br><br>\n\n";

                  printLogOutButton('individual_search.php');
                  echo "\n\n";

                  echo "<script>\n";
                  echo "function Validate(form)\n";
                  echo "{\n";
                  echo "$jscript\n";
                  echo "</script>\n";
                }#end if Want analysis files, but haven't selected which analyses

	      #9	     Get Genotypes and Phenotypes 
	      #10	     Call download.php
	      if (
		  (
		   (preg_match('/\w+/',$status)) and
		   (sizeof($marker_ids) > '0') and
                   ($marker_multiple_pages == '0') and
                   (!preg_match('/\d/',$pheno_multiple_pages)) and
                   ($create_analysis_files == '0')
		  ) or
                  (
		   (preg_match('/\w+/',$status)) and
		   (sizeof($marker_ids) > '0') and
                   ($marker_multiple_pages == '0') and
		   (!preg_match('/\d/',$pheno_multiple_pages)) and
                   ($create_analysis_files == '1') and
                   (preg_match('/\d+/',$analysis_option))
		  ) or
		  (
		   (preg_match('/\w+/',$status)) and
		   (sizeof($marker_ids) > '0') and
		   ($marker_multiple_pages == '0') and
		   (sizeof($pheno_ids) > '0') and
                   ($pheno_multiple_pages == '0') and
                   ($create_analysis_files == '0')
		  )or
                  (
		   (preg_match('/\w+/',$status)) and
		   (sizeof($marker_ids) > '0') and
		   ($marker_multiple_pages == '0') and
		   (sizeof($pheno_ids) > '0') and
                   ($pheno_multiple_pages == '0') and
                   ($create_analysis_files == '1') and
                   (preg_match('/\d+/',$analysis_option))
		  )
		 )
                {
		 echo "The data you requested is being prepared to be downloaded.  When the page finishes loading, click the \"Download Data\" button \n";
                 echo "and you can download the data to your computer:<br><br>\n";

                 $rand = rand();
                 $file_name = "download_genotype_record_".$rand.".txt";
                 $parameter_file_name = "parameter_string_".$rand.".txt";

                 $parameter_file_handle = fopen("../bin/database_query_scripts/$parameter_file_name","w");
                 if (!$parameter_file_handle)
                   {
                     $date = date('Y-m-d H:i:s');
                     echo "Error #296: $date<br>\n";
                     echo "Error in call to fopen from individual_search.php<br>\n";
                     echo "Unable to print file $file_name in data/download_data/<br><br>\n";
                     echo "Please email the above error using Comments/Help/Support link \n";
                     echo "in the left navigation bar.<br>\n";
                     echo "</body></html>\n";
                     $ret_val = disconnect();
                     exit;
                   }#end if can't open parameter file

                 if (!is_array($individual_ids)){$indiv_term = $individual_ids;}
                 else                           {$indiv_term = join($individual_ids,',');}

                 if (!is_array($marker_ids)){$marker_term = $marker_ids;}
                 else                       {$marker_term = join($marker_ids,',');}

                 if (sizeof($pheno_ids) > 0)
                   {
                     if (!is_array($pheno_ids)){$pheno_term = $pheno_ids;}
                     else                      {$pheno_term = join($pheno_ids,',');}
                   }#end if have phenotypes

                 $field_list_array = array('individual_table_id');
                 $num_of_indivs = countTableQuery('individual_table',$database_id,$field_list_array,$indiv_term,'in');
                 if (!preg_match('/^\d+$/',$num_of_indivs))
                   {
                     $date = date('Y-m-d H:i:s');
                     echo "Error #297: $date<br>\n";
                     echo "Error in call to countTableQuery from individual_search.php<br>\n";
                     echo "$num_of_indivs<br><br>\n";
                     echo "Please email the above error using the Comments/Help/Support link on the \n";
                     echo "left navigation bar.\n";
                     echo "</form>\n";
                     echo "</body></html>\n";
                     $ret_val = disconnect();
                     exit;
                   }#end error in call to countTableQuery

                 $field_list_array = array('marker_id');
                 $num_of_markers = countTableQuery('marker_table',$database_id,$field_list_array,$marker_term,'in');
                 if (!preg_match('/^\d+$/',$num_of_markers))
                   {
                     $date = date('Y-m-d H:i:s');
                     echo "Error #298: $date<br>\n";
                     echo "Error in call to countTableQuery from individual_search.php<br>\n";
                     echo "$num_of_markers<br><br>\n";
                     echo "Please email the above error using the Comments/Help/Support link on the \n";
                     echo "left navigation bar.\n";
                     echo "</form>\n";
                     echo "</body></html>\n";
                     $ret_val = disconnect();
                     exit;
                   }#end error in call to countTableQuery

                 if (sizeof($pheno_ids) > 0)
                   {
                     $field_list_array = array('phenotype_id');
                     $num_of_phenos = countTableQuery('phenotype_table',$database_id,$field_list_array,$pheno_term,'in');
                     if (!preg_match('/^\d+$/',$num_of_phenos))
                       {
                         $date = date('Y-m-d H:i:s');
                         echo "Error #299: $date<br>\n";
                         echo "Error in call to countTableQuery from individual_search.php<br>\n";
                         echo "$num_of_phenos<br><br>\n";
                         echo "Please email the above error using the Comments/Help/Support link on the \n";
                         echo "left navigation bar.\n";
                         echo "</form>\n";
                         echo "</body></html>\n";
                         $ret_val = disconnect();
                         exit;
                       }#end error in call to countTableQuery
                   }#end if have phenotypes

                 $type_of_query = "genotype_record";
                 $print_string = "indiv_list:$indiv_term\n";
                 $print_string.= "marker_list:$marker_term\n";
                 $print_string.= "status:$status\n";
                 $print_string.= "file_name:$file_name\n";
                 if (sizeof($pheno_ids) > 0) {$print_string.= "pheno_list:$pheno_term";}
                 if ($create_analysis_files)
                   {
                     $print_string.= "analysis_option:$analysis_option\n";
                     if (!is_array($analysis_sub_option)){$print_string.= "analysis_sub_option:$analysis_sub_option\n";}
                     else #is an array
                       {
                         $sub_string = "";
                         foreach ($analysis_sub_option as $sub_option){$sub_string.= "$sub_option ";}
                         $sub_string = preg_replace('/ $/','',$sub_string);
                         $print_string.= "analysis_sub_option:$sub_string\n";
                       }#end if analysis_sub_option is an array
                     if (sizeof($r_plot_statistics) > 0)
                       {
                         $sub_string = "";
                         foreach ($r_plot_statistics as $stat){$sub_string.= "$stat ";}
                         $sub_string = preg_replace('/ $/','',$sub_string);
                         $print_string.= "r_plot_statistics:$sub_string";
                         $print_string.= " e\n";
                       }#end if plot statistics
                   }#end if want to generate analysis files
                 
                 $ret_val = fwrite($parameter_file_handle,$print_string);
                 if (!$ret_val)
                   {
                     $date = date('Y-m-d H:i:s');
                     echo "Error #300: $date<br>\n";
                     echo "Error in call to fwrite from individual_search.php<br>\n";
                     echo "Unable to write to parameter file handle for file $parameterfile_name in /bin/database-query_scripts/<br><br>\n";
                     echo "Please email the above error using the Comments/Help/Support link on the \n";
                     echo "left navigation bar.\n";
                     echo "</form>\n";
                     echo "</body></html>\n";
                     $ret_val = disconnect();
                     exit;
                   }#end error in call to fwrite

                 $ret_val = fclose($parameter_file_handle);
                 if (!$ret_val)
                   {
                     $date = date('Y-m-d H:i:s');
                     echo "Error #301: $date<br>\n";
                     echo "Error in call to fclose from individual_search.php<br>\n";
                     echo "Unable to close parameter file handle for file $parameterfile_name in /bin/database_query_scripts/<br><br>\n";
                     echo "Please email the above error using the Comments/Help/Support link on the \n";
                     echo "left navigation bar.\n";
                     echo "</form>\n";
                     echo "</body></html>\n";
                     $ret_val = disconnect();
                     exit;
                   }#end error in call to fclose

	         $ret_val = chdir("../bin/database_query_scripts/");
                 if (!$ret_val)
                   {
                     $date = date('Y-m-d H:i:s');
                     echo "Error #302: $date<br>\n";
                     echo "Error in call to chdir from individual_search.php<br>\n";
                     echo "Unable to change directory to database query scripts directory<br><br>\n";
                     echo "Please email the above error using Comments/Help/Support link \n";
	             echo "in the left navigation bar.<br>\n";
	             echo "</body></html>\n";
                     $ret_val = disconnect();
                     exit;
                   }#end error in call to chdir

                 if (sizeof($pheno_ids) > 0)
                   {
                     if (($num_of_indivs*($num_of_markers+$num_of_phenos)) > $max_records_to_wait_to_run){$background_flag = 1;}
                     else                                                                                {$background_flag = 0;}
                   }#end if have phenotypes
                 else #no phenotypes
                   {
                     if (($num_of_indivs*$num_of_markers) > $max_records_to_wait_to_run){$background_flag = 1;}
                     else                                                               {$background_flag = 0;}
                   }#end else no phenotypes
                 $command = "./query_and_write_results.php '$parameter_file_name'  '$database_id' '$_SESSION[user_name]'  'Individual Search' '$background_flag' '$type_of_query' '$create_analysis_files'";
                 if ($background_flag)
                   {
                     $command.= " > dummy_query_and_write_results_background_output.txt &";
                     $last_line = system($command,$sys_ret_val);
                   }#end if run in the background
                 else #run in the foreground
                   {
                     passthru($command,$sys_ret_val);
                   }#end if run in the foreground

                 $ret_val = chdir("../../cgi-bin/");
                 if (!$ret_val)
                   {
                     $date = date('Y-m-d H:i:s');
                     echo "Error #303: $date<br>\n";
                     echo "Error in call to chdir from individual_search.php<br>\n";
                     echo "Unable to change directory to cgi-bin directory<br><br>\n";
                     echo "Please email the above error using Comments/Help/Support link \n";
	             echo "in the left navigation bar.<br>\n";
	             echo "</body></html>\n";
                     $ret_val = disconnect();
                     exit;
                   }#end error in call to chdir

                 if ($sys_ret_val != '0')
	           {
	             $date = date('Y-m-d H:i:s');
	             echo "Error #304: $date<br>\n";
	             echo "Error in system call to query_and_write_results.php from individual_search.php<br>\n";
	             echo "The return value of the sytem call was $sys_ret_val<br>\n";
                     if ($background_flag){echo "The last line of output was: $last_line<br><br>\n";}
                     echo "Please email the above error using the Comments/Help/Support link on the \n";
	             echo "left navigation bar.\n";
	             echo "</form>\n";
	             echo "</body></html>\n";
	             $ret_val = disconnect();
	             exit;
	           }#end if error in system call

                 if ($background_flag)
                   {
	             echo "<center>\n";
	             echo "<b>The data you requested to download is being prepared.<br>\n";
	             echo "You will receive an email when the data is ready to be downloaded.<br>\n";
	             echo "Follow the instructions in the email to retrieve your data.</b><br><br>\n";
	             echo "</center>\n";
                   }#end if queries run in the background
	         else #queries not run in the background
                   {
                     if ($create_analysis_files)
                       {
                         echo "<form action=\"download.php\" name=\"form\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(this))\">\n"; 
                         echo "<br><br>\n";
                         echo "Below are the data files generated by the application and Mega2 based upon your selections.  Please select them \n";
                         echo "one at a time and click 'Download File' to download the file to your computer:<br><br>\n";
                         $dir_handle = opendir("../data/download_data/$_SESSION[user_name]/");
                         echo "<table align=\"center\">\n";
                         echo "<tr>\n";
                         echo "<td>Data Files:</td><td>\n";
                         echo "<select name=\"file_name\">\n";
                         echo "<option>Select File to Download\n";
                         while ($file = readdir($dir_handle))
                           {
                             if (preg_match("/$rand/",$file)){echo "<option value=\"../data/download_data/$_SESSION[user_name]/$file\">$file\n";}
                           }#end while files in download data directory
                         echo "</select>\n";
                         echo "</td>\n";
                         echo "</tr>\n";
                         echo "</table>\n";
                         echo "<br><br>\n\n";

                         echo "<input type=\"hidden\" name=\"type_of_download\" value=\"\">\n";
                         echo "<center>\n";
                         echo "<input type=\"submit\" name=\"submit\" value=\"Download Selected File\">\n";
                         echo "</center>\n";
                       }#end if created_analysis files
                     else #did not create analysis files
                       {
                         echo "<form action=\"download.php\" name=\"form\" method=\"POST\" target=\"main\">\n";# onSubmit=\"return(Validate(this))\">\n"; 
                         echo "<input type=\"hidden\" name=\"file_name\" value=\"../data/download_data/$_SESSION[user_name]/$file_name\">\n";
                         echo "<input type=\"hidden\" name=\"type_of_download\" value=\"genotype_record\">\n";
	                 echo "<center>\n";
	                 echo "<input type=\"submit\" name=\"submit\" value=\"Download Selected Records\">\n";
                         echo "</center>\n";
                       }#end else did not create analysis files
                     echo "</form>\n";
                     echo "<br><br>\n";

                     $ret_val = printLogOutButton('individual_search.php');
	             echo "\n\n";

                     if ($create_analysis_files)
                       {
                         echo "<script>\n";
                         echo "function Validate(form)\n";
                         echo "{\n";
                         echo "  if (form.file_name.selectedIndex == 0){\n";
                         echo "    alert(\"You must select a File to Download\");\n";
                         echo "    form.file_name.focus();\n";
                         echo "    return(false);}\n";
                         echo "  else{return(true);}\n";
                         echo "}\n";
                         echo "</script>\n";
                       }#end if created analysis files
                   }#end else queries not run in the background
	        }#end if have status, marker_ids, and pheno_ids
	     }#end if (sizeof(indiv_ids) > '0')
	  }#end if (auth_user == '1')
$ret_val = disconnect(); 
echo "</body>\n";
echo "</html>\n";

function tooManyIndividuals()
{
  $individual_table_id_list = func_get_arg(0);

  echo "This number of individuals is too large to practically and efficiently display and select over the web.<br>\n";
  echo "If you would like to download the information on the individuals returned or get genotype information for all \n";
  echo "the individuals returned from your search, please click the appropriate button below:<br><br>\n";

  echo "<table align=\"center\">\n";
  echo "<form action=\"download.php\" name=\"download\" method=\"POST\" target=\"main\">\n";
  echo "<input type=\"hidden\" name=\"type_of_download\" value=\"individual_record\">\n";
  echo "<input type=\"hidden\" name=\"indiv_id\" value=\"$individual_table_id_list\">\n";
  echo "<tr>\n";
  echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download All Individuals' Information\"></td>\n";
  echo "</form>\n";

  echo "<form action=\"individual_search.php\" name=\"form3\" method=\"POST\" target=\"main\">\n";
  echo "<input type=\"hidden\" name=\"individual_flag\" value=\"1\">\n";
  echo "<input type=\"hidden\" name=\"indiv_multiple_pages\" value=\"0\">\n";
  echo "<input type=\"hidden\" name=\"indiv_id\" value=\"$individual_table_id_list\">\n";
  echo "<td align=\"center\"><input type=\"submit\" name=\"submit3\" value=\"Get Genotypes for All Individuals\"></td>\n";
  echo "</form>\n";
  echo "</tr>\n";
  echo "</table>\n";
  echo "<br><br>\n";
  echo "Or I suggest that you refine your search criteria and try another search using the \"Individual Search\" tool.<br>\n";
  echo "</body>\n";
  echo "</html>\n";
}#end function tooManyIndividuals

function moreThanFivePages()
{
  $individual_table_id_list = func_get_arg(0);

  echo "<hr>\n";
  echo "<br>\n";
  echo "If would like to download information on or get genotypes for all the individuals returned by your search,<br>\n";
  echo "without investigating each one, click the appropriate button below:<br><br>\n";

  echo "<table align=\"center\">\n";
  echo "<form action=\"download.php\" name=\"download2\" method=\"POST\" target=\"main\">\n";
  echo "<input type=\"hidden\" name=\"type_of_download\" value=\"individual_record\">\n";
  echo "<input type=\"hidden\" name=\"indiv_id\" value=\"$individual_table_id_list\">\n";
  echo "<tr>\n";
  echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download All Individual's Information\"></td>\n";
  echo "</form>\n";

  echo "<form action=\"individual_search.php\" name=\"form2\" method=\"POST\" target=\"main\">\n";
  echo "<input type=\"hidden\" name=\"individual_flag\" value=\"1\">\n";
  echo "<input type=\"hidden\" name=\"indiv_multiple_pages\" value=\"0\">\n";
  echo "<input type=\"hidden\" name=\"indiv_id\" value=\"$individual_table_id_list\">\n";
  echo "<td align=\"center\"><input type=\"submit\" name=\"submit2\" value=\"Get Genotypes for All Individuals\"></td>\n";
  echo "</form>\n";
  echo "</tr>\n";
  echo "</table>\n";
  echo "<br>\n";
  echo "<hr>\n";
  echo "<br><br><br>\n";
  echo "Otherwise, continue below to select the individuals you would like information for.<br><br>\n";
}#end function moreThanFivePages
?>
Return current item: Generic Genetic Studies Database