Location: PHPKode > projects > Generic Genetic Studies Database > ggsd-2.19/cgi-bin/marker_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 'html_lib.inc';
require 'sql_lib.inc';
require 'file_system_lib.inc';


#NAME	marker_search.php

#TYPE	PHP

#USES	sql_lib(authenticate tableQuery distinctTableQuery tableJoin distinctTableJoin compoundTableQuery)
#	html_lib(printTableSelectList printStatusSelectList printSearchPage printMarkerCheckList
#	         printPhenotypeCheckList printGenotypeCheckList)

#PURPOSE	To allow the user to search any table in the database and get a list
#	of markers that meet their search criteria.  The user can then get
#	genotypes for all individuals in the database for those markers.

#USAGE	marker_search.php

#PARAMETERS
#	table name	table_name	string		optional
#	field list	field_list	checkbox list	optional
#	term		term		string		optional
#	mode		mode		string		optional
#	marker ids	marker_ids	checkbox list	optional
#	phenotype ids	pheno_ids	checkbox list	optional
#	status		status		string		optional
#	submit		submit		string		optional

#RETURNS
#	marker ids	marker_ids	checkbox list	if success
#	phenotype ids	pheno_ids	checkbox list	if success
#	genotype recs	genotype_record checkbox list	if success
#	error message					if error

#DATASTRUCTURES The parameters described as checkbox lists are checkboxes
#	       that have the same name but different values.  The result
#	       is an array of values for one checkbox name.

#FUNCTIONAL DESCRIPTION The script will authenticate the user.  Then provide
#		       them with a table select list.  Then provide a search page
#		       specific for the chosen table.  Then based upon search criteria
#		       the user will be presented with a checkbox list of markers that
#		       met their search criteria.  The user can then select which markers
#		       to see genotypes for in every individual in the database.  You user
#		       can also select to get data on phenotypes.  The user is then given
#		       a table of records then can select to download.

#ASSUMPTIONS That the ultimate goal of the user is to get a list of records that
#	    contain genotypes for individuals for the found markers and download
#	    to their hard drive for analysis.

#LIMITATIONS The user will not be able to select which individuals to get genotypes for
#	    until the final download step.

#COMMENTS

#PRELIMINARY DESIGN
#	    1	Get Args
#	    2	Authenticate user
#	    3	Print Table Select List
#	    4	Print Search Page
#	    5	Execute Query and Print Marker Check List
#	    6	Print Phenotype CheckList
#	    7	Print Genotype Check List
#	    8	Call download script

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>Marker Search</title>\n";
echo " </head>\n";
 
echo "<body bgcolor = \"white\">\n";
echo "<center><h3>Marker Search</h3></center>\n";
echo "<hr>\n";
printHomeNavBar();
echo "<br>\n";


	#1	Get Args
$access_type_required  = 'search';
$DEBUG = 0;
$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'];
$marker_flag           = $_POST['marker_flag'];
$marker_multiple_pages = $_POST['marker_multiple_pages'];
$marker_ids            = $_POST['marker_id'];
$pheno_multiple_pages  = $_POST['pheno_multiple_pages'];
$pheno_ids             = $_POST['pheno_id'];
$ped_flag              = $_POST['ped_flag'];
$ped_multiple_pages    = $_POST['ped_multiple_pages'];
$ped_ids               = $_POST['ped_id'];
$status                = $_POST['status'];
$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 "<table>\n";
    echo "<tr><td>table_name</td><td>$table_name</td></tr>\n";
    echo "<tr><td>field_list</td><td>$field_list</td></tr>\n";
    echo "<tr><td>term</td><td>$term</td></tr>\n";
    echo "<tr><td>term</td><td>$mode</td></tr>\n";
    echo "<tr><td>join</td><td>$join</td></tr>\n";
    echo "<tr><td>order_by</td><td>$order_by</td></tr>\n";
    echo "<tr><td>function_to_call</td><td>$function_to_call</td></tr>\n";
    echo "<tr><td>last_record_retrieved</td><td>$last_record_retrieved</td></tr>\n";
    echo "<tr><td>marker_flag</td><td>$marker_flag</td></tr>\n";
    echo "<tr><td>marker_multiple_pages</td><td>$marker_multiple_pages</td></tr>\n";
    echo "<tr><td>marker_ids</td><td>$marker_ids</td></tr>\n";
    echo "<tr><td>pheno_multiple_pages</td><td>$pheno_multiple_pages</td></tr>\n";
    echo "<tr><td>pheno_ids</td><td>$pheno_ids</td></tr>\n";
    echo "<tr><td>ped_flag</td><td>$ped_flag</td></tr>\n";
    echo "<tr><td>status</td><td>$status</td></tr>\n";
    echo "<tr><td>submit</td><td>$submit</td></tr>\n";
    echo "</table>\n";
    echo "<br><br>\n";
  }#end if DEBUG turned on

$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 marker_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	Authenticate 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 marker_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 marker_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('marker_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 marker_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 marker_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 marker_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 marker_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('marker_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 marker_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('marker_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 marker_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 marker_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 ($marker_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 "<form action=\"marker_search.php\" name=\"form\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(this))\">\n";
	    echo "This form will allow you to search for markers in the database using search criteria from any of the \n";
	    echo "tables in the database.  You will first need to select the table that the search criteria \n";
	    echo "will be used to find the markers of interest.  You will then be able to select which fields in that table \n";
	    echo "you want to search, enter in a search term, and select the type or mode of search to conduct.  You will \n";
	    echo "then be presented with a list of markers that meet your search criteria.  You can then select which markers you \n";
	    echo "would like genotypes for.  Select an affection status to investigate and which markers you want genotypes for.  \n";
	    echo "If you also want phenotype data click on the Select Phenotypes button.  You will then be given a list of all the \n";
	    echo "individuals in the database and their genotypes for the selected markers.  You can then select all or a subset of the data to download.<br><br>\n";
	    echo "<center>\n";
	    echo "Select a Table to Search:<br>\n";
	    $jscript = printTableSelectList();
	    if ($jscript == '0')
	      {
		echo "</center>\n";
		$date = date('Y-m-d H:i:s');
		echo "Error #11: $date<br>\n";
		echo "Error in call to printTableSelectList from marker_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 the \n";
		echo "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=\"Find Markers\">\n";
	    echo "<input type=\"reset\" name=\"reset\" value=\"Reset Selection\">\n";
            echo "</form>\n";
            echo "</center>\n";
            echo "<br><br>\n";

            $ret_val = printLogOutButton('marker_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,term,and mode

	#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=\"marker_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";
	    $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 marker_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 the \n";
		echo "left navigation bar.\n";
		echo "</form>\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end if (jscript == '0')
	    echo "<input type=\"hidden\" name=\"table_name\" value=\"$table_name\">\n";
	    echo "<center>\n";
	    echo "<input type=\"submit\" name=\"submit\" value=\"Find Markers\">\n";
	    echo "<input type=\"reset\" name=\"reset\" value=\"Reset Selections\">\n";
            echo "</form>\n";
            echo "</center>\n";
            echo "<br><br>\n";

            $ret_val = printLogOutButton('marker_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 not field_list,term,mode

	#5	  Execute Query and Print Marker 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 "Please select the Affection Status and Markers you want to investigate:<br><br>\n";
            if ($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_mode = $mode[$i];
                            $search_term = $term[$i];
                          }
                      }#end determine which mode and term to use

                    $num_markers = countTableQuery($table_name,$database_id,$field_list,$search_term,$search_mode);
                    if (!preg_match('/^\d+$/',$num_markers))
                      {
                        $date = date('Y-m-d H:i:s');
		        echo "Error #13: $date<br>\n";
		        echo "Error in call to countTableQuery from marker_search.php<br>\n";
		        echo "$num_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 if error in call to countTableQuery

                    #if ($num_markers > $max_records_to_print)
                    #  {
                    #    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',$table_name,$database_id,$field_list,$search_term,$search_mode,'all',$order_by);
		#	if (!is_array($marker_id_array))
                #          {
                #            $date = date('Y-m-d H:i:s');
		#            echo "Error #14: $date<br>\n";
		#            echo "Error in call to distinctTableQuery from marker_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_list = join($marker_id_array,',');
                #        unset($marker_id_array);

                #        echo "Your search returned $num_markers markers.<br>\n";
                #        tooManyMarkers($marker_id_list);
                #        $ret_val = disconnect();
                #        exit;
                #      }#end if more than $max_records_to_print

                    if ($num_markers > (5 * $max_records_to_print_per_page))
                      {
                        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',$table_name,$database_id,$field_list,$search_term,$search_mode,'all',$order_by);
			if (!is_array($marker_id_array))
                          {
                            $date = date('Y-m-d H:i:s');
		            echo "Error #15: $date<br>\n";
		            echo "Error in call to distinctTableQuery from marker_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_list = join($marker_id_array,',');
                        unset($marker_id_array);

                        moreThanFivePages($marker_id_list);
                        unset($marker_id_list);
                      }#end if more than 5 pages of records

                    if ($num_markers > $max_records_to_print_per_page)
                      {
                        $marker_multiple_pages = 1;
                        $from                  = 0;
                        $to                    = $max_records_to_print_per_page - 1;
                        $range                 = "$from"."-"."$to";
                        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($table_name,$database_id,$field_list,$search_term,$search_mode,$range,$order_by);
		        if (!is_array($marker_rec_list))
		          {
		            $date = date('Y-m-d H:i:s');
		            echo "Error #16: $date<br>\n";
		            echo "Error in call to tableQuery from marker_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')
		          {
		            echo "Your search of the Marker Table did not yield any markers.<br>\n";
		            echo "Please change your search criteria and try a new search.<br>\n";
                            echo "<form action=\"marker_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 if (sizeof(marker_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 num_of_markers > max_records_to_print_per_page
                    else #($num_markers <= max_records_to_print_per_page)
                      {
                        $marker_multiple_pages = 0;
                        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($table_name,$database_id,$field_list,$search_term,$search_mode,'all',$order_by);
		        if (!is_array($marker_rec_list))
		          {
		            $date = date('Y-m-d H:i:s');
		            echo "Error #17: $date<br>\n";
		            echo "Error in call to tableQuery from marker_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')
		          {
		            echo "Your search of the Marker Table did not yield any markers.<br>\n";
		            echo "Please change your search criteria and try a new search.<br>\n";
                            echo "<form action=\"marker_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 if (sizeof(marker_rec_list) == '0')
                      }#end if less than or equal max_records_to_print_per_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 determine term and mode to use

                    $num_markers = countCompoundTableQuery($table_name,$database_id,$field_list,$term_array,$mode_array,$join);
                    if (!preg_match('/^\d+$/',$num_markers))
                      {
                        $date = date('Y-m-d H:i:s');
			echo "Error #18: $date<br>\n";
			echo "Error in call to countCompoundTableQuery from marker_search.php<br>\n";
			echo "$num_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 countCompoundTableQuery

                    #if ($num_markers > $max_records_to_print)
                    #  {
                    #    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 = distinctCompoundTableQuery('marker_id',$table_name,$database_id,$field_list,$term_array,$mode_array,$join,'all',$order_by);
                    #    if (!is_array($marker_id_array))
                    #      {
                    #        $date = date('Y-m-d H:i:s');
                    #        echo "Error #19: $date<br>\n";
                    #        echo "Error in call to distinctCompoundTableQuery from marker_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
                    #    $marker_id_list = join($marker_id_array,',');
                    #    unset($marker_id_array);

                    #    echo "Your search returned $num_markers markers.<br>\n";
                    #    tooManyMarkers($marker_id_list);
                    #    $ret_val = disconnect();
                    #    exit;
                    #  }

                    if ($num_markers > (5 * $max_records_to_print_per_page))
                      {
                        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 = distinctCompoundTableQuery('marker_id',$table_name,$database_id,$field_list,$term_array,$mode_array,$join,'all',$order_by);
                        if (!is_array($marker_id_array))
                          {
                            $date = date('Y-m-d H:i:s');
                            echo "Error #20: $date<br>\n";
                            echo "Error in call to distinctCompoundTableQuery from marker_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
                        $marker_id_list = join($marker_id_array,',');
                        unset($marker_id_array);

                        moreThanFivePages($marker_id_list);
                        unset($marker_id_list);
                      }#end if more than 5 pages of records

                    if ($num_markers > $max_records_to_print_per_page)
                      {
                        $marker_multiple_pages = 1;
                        $from  = 0;
                        $to    = $max_records_to_print_per_page - 1;
                        $range = "$from"."-"."$to";
                        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 = compoundTableQuery($table_name,$database_id,$field_list,$term_array,$mode_array,$join,$range,$order_by);
		        if (!is_array($marker_rec_list))
		          {
			    $date = date('Y-m-d H:i:s');
			    echo "Error #21: $date<br>\n";
			    echo "Error in call to compoundTableQuery from marker_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 error in call to compoundTableQuery
		        if (sizeof($marker_rec_list) == '0')
		          {
			    echo "Your search of the Marker Table did not yield any markers.<br>\n";
		            echo "Please change your search criteria and try a new search.<br>\n";
                            echo "<form action=\"marker_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 if sizeof(marker_rec_list) == '0'
                        $final_function_call   = 'compoundTableQuery';
			$final_table_name      = $table_name;
			$final_field_list      = $field_list;
			$final_term            = $term_array;
			$final_mode            = $mode_array;
                        $final_join            = $join;
			$final_order_by        = $order_by;
                        $last_record_retrieved = $max_records_to_print_per_page;
		      }#end if num_of_markers > max_records_to_print_per_page
                    else #($num_markers <= max_records_to_print_per_page)
                      {
                        $marker_multiple_pages = 0;
                        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 = compoundTableQuery($table_name,$database_id,$field_list,$term_array,$mode_array,$join,'all',$order_by);
		        if (!is_array($marker_rec_list))
		          {
			    $date = date('Y-m-d H:i:s');
			    echo "Error #22: $date<br>\n";
			    echo "Error in call to compoundTableQuery from marker_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 error in call to compoundTableQuery
		        if (sizeof($marker_rec_list) == '0')
		          {
			    echo "Your search of the Marker Table did not yield any markers.<br>\n";
		            echo "Please change your search criteria and try a new search.<br>\n";
                            echo "<form action=\"marker_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 if sizeof(marker_rec_list) == '0'
                      }#end if less than or equal max_records_to_print_per_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 #23:$date<br>\n";
                            echo "Error in call to distinctTableJoin from marker_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 markers.<br>\n";
		            echo "Please try a new search with different search criteria.<br>\n";
			    echo "<form action=\"marker_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 #24:$date<br>\n";
                            echo "Error in call to distinctTableJoin from marker_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 markers.<br>\n";
		            echo "Please try a new search with different search criteria.<br>\n";
			    echo "<form action=\"marker_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 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 #25:$date<br>\n";
                            echo "Error in call to distinctCompoundTableQuery from marker_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 markers.<br>\n";
		                echo "Please try a new search with different search criteria.<br>\n";
			        echo "<form action=\"marker_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 #26:$date<br>\n";
                            echo "Error in call to distinctCompoundTableQuery from marker_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 markers.<br>\n";
		                echo "Please try a new search with different search criteria.<br>\n";
			        echo "<form action=\"marker_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 #27:$date<br>\n";
                        echo "Error in call to distinctCompoundTableQuery from marker_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 markers.<br>\n";
		        echo "Please try a new search with different search criteria.<br>\n";
			echo "<form action=\"marker_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');
                $num_markers = countTableQuery('marker_table',$database_id,$field_list_array,$marker_id_term,'in');
                if (!preg_match('/^\d+$/',$num_markers))
                  {
                    $date = date('Y-m-d H:i:s');
                    echo "Error #28: $date<br>\n";
                    echo "Error in call to countTableQuery from marker_search.php<br>\n";
                    echo "$num_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_markers == '0')
                  {
                    echo "<center>\n";
		    echo "Your search of the Map Table did not yield any markers.<br>\n";
		    echo "Please try a new search with different search criteria.<br>\n";
		    echo "<form action=\"marker_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_markers > $max_records_to_print_per_page)
                  {
                    $marker_multiple_pages = 1;
                    $from                  = "0";
                    $to                    = $max_records_to_print_per_page - 1;
                    $range                 = "$from"."-"."$to";
                    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,$marker_id_term,'in',$range,$order_by);
                    if (!is_array($marker_rec_list))
                      {
                        $date = date('Y-m-d H:i:s');
                        echo "Error #29: $date<br>\n";
                        echo "Error in call to tableQuery from marker_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 "</body></html>\n";
                        $ret_val = disconnect();
                        exit;
                      }#end if error in call to tableQuery
                    $final_function_call   = 'tableQuery';
                    $final_table_name      = 'marker_table';
                    $final_field_list      = $field_list_array;
                    $final_term            = $marker_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
                  {
                    $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,$marker_id_term,'in',$range,$order_by);
                    if (!is_array($marker_rec_list))
                      {
                        $date = date('Y-m-d H:i:s');
                        echo "Error #30: $date<br>\n";
                        echo "Error in call to tableQuery from marker_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 "</body></html>\n";
                        $ret_val = disconnect();
                        exit;
                      }#end if error in call to tableQuery
                  }#end else only a single page
              }#end elseif (table_name == 'map_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];
			    }
			}

                      if (preg_match('/number_.+_affected_in_pedigree/',$field_list[0]))
                        {
                          preg_match('/number_(.+)_affected_in_pedigree/',$field_list[0],$captured);
                          $affection_name = $captured[1];
                          $affect_field_list = array('affection_status_name');
                          $affect_id_array = distinctTableQuery('affection_status_id','affection_status_table',$database_id,$affect_field_list,$affection_name,'equal','all');
                          if (!is_array($affect_id_array))
                            {
                              $date = date('Y-m-d H:i:s');
                              echo "Error #31: $date<br>\n";
                              echo "Error in call to distinctTableQuery from marker_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')
                            {
                              echo "<center>\n";
			      echo "Your search of the Pedigree Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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(affect_id_array) == '0')
                          elseif (sizeof($affect_id_array) == '1') {$affect_id = $affect_id_array[0];}
                          else
                            {
                              $date = date('Y-m-d H:i:s');
                              echo "Error #32: $date<br>\n";
                              echo "User wanted to search for pedigrees with $search_term[0] affected for 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

                          $ped_affect_field_list = array('affection_status_id','number_affected_in_pedigree');
                          $ped_affect_term_array = array($affect_id,$search_term);
                          $ped_affect_mode_array = array('equal',$search_mode);
                          $ped_id_array = distinctCompoundTableQuery('pedigree_table_id','pedigree_affection_status_link_table',$database_id,$ped_affect_field_list,$ped_affect_term_array,$ped_affect_mode_array,'all');
                          if (!is_array($ped_id_array))
                            {
                              $date = date('Y-m-d H:i:s');
                              echo "Error #33: $date<br>\n";
                              echo "Error in call to distinctCompoundTableQuery from marker_search.php<br>\n";
                              echo "$ped_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 markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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
                          else #have records
                            {
                              $ped_table_id_term = join($ped_id_array,',');
                              unset($ped_id_array);
                            
                              $field_list = array('pedigree_table_id');
                              $rec_list   = distinctTableQuery('individual_table_id','individual_table',$database_id,$field_list,$ped_table_id_term,'in','all');
                              if (!is_array($rec_list))
                                {
                                  $date = date('Y-m-d H:i:s');
                                  echo "Error #34: $date<br>\n";
                                  echo "Error in call to distinctTableQuery from marker_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 distinctTableQuery
                              if (sizeof($rec_list) == '0')
                                {
                                  echo "<center>\n";
			          echo "Your search of the Pedigree Table did not yield any markers.<br>\n";
			          echo "Please change your search criteria and try a new search.<br>\n";
                                  echo "<form action=\"marker_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($ped_table_id_term);
                              unset($rec_list);
                            }#end else have records
                        }#end if affection status field
                      else #pedigree table field  
                        {
		          $rec_list = distinctTableJoin('individual_table_id',$table_name,'individual_table',$database_id,$field_list,$search_term,$search_mode,'all');
		          if (!is_array($rec_list))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #35: $date<br>\n";
			      echo "Error in call to distinctTableJoin from marker_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 "Your search of the Pedigree Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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 if (sizeof(rec_list) == '0')
		          $indiv_table_id_term = join($rec_list,',');
                          unset($rec_list);
                        }#end else pedigree table field

		      $field_list_array = array('individual_table_id');
		      $rec_list = distinctTableQuery('marker_id','genotype_table',$database_id,$field_list_array,$indiv_table_id_term,'in','all');
		      if (!is_array($rec_list))
			{
			  $date = date('Y-m-d H:i:s');
			  echo "Error #36: $date<br>\n";
			  echo "Error in call to distinctTableQuery from marker_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 "Your search of the Pedigree Table did not yield any markers.<br>\n";
			  echo "Please change your search criteria and try a new search.<br>\n";
                          echo "<form action=\"marker_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 if (sizeof(rec_list) == '0')

		      $term = join($rec_list,',');
		      $field_list_array = array('marker_id');
                      unset($rec_list);
                      unset($indiv_table_id_term);

                      $num_markers = countTableQuery('marker_table',$database_id,$field_list_array,$term,'in');
                      if (!preg_match('/^\d+$/',$num_markers))
                        {
                          $date = date('Y-m-d H:i:s');
			  echo "Error #37: $date<br>\n";
			  echo "Error in call to countTableQuery from marker_search.php<br>\n";
			  echo "$num_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 if error in call to countTableQuery

                      #if ($num_markers > $max_records_to_print)
                      #  {
                      #    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,$term,'in','all',$order_by);
                      #    if (!is_array($marker_id_array))
                      #      {
                      #        $date = date('Y-m-d H:i:s');
                      #        echo "Error #38: $date<br>\n";
                      #        echo "Error in call to distinctTableQuery from marker_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_list = join($marker_id_array,',');
                      #    unset($marker_id_array);

                      #    echo "Your search returned $num_markers markers.<br>\n";
                      #    tooManyMarkers($marker_id_list);
                      #    $ret_val = disconnect();
                      #    exit;
                      #  }#end if more records that allowable to print

                      if ($num_markers > (5 * $max_records_to_print_per_page))
                        {
                          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,$term,'in','all',$order_by);
                          if (!is_array($marker_id_array))
                            {
                              $date = date('Y-m-d H:i:s');
                              echo "Error #39: $date<br>\n";
                              echo "Error in call to distinctTableQuery from marker_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_list = join($marker_id_array,',');
                          unset($marker_id_array);

                          moreThanFivePages($marker_id_list);
                          unset($marker_id_list);
                        }#end if more than 5 pages of markers

                      if ($num_markers > $max_records_to_print_per_page)
                        {
                          $marker_multiple_pages = 1;
                          $from  = 0;
                          $to    = $max_records_to_print_per_page - 1;
                          $range = "$from"."-"."$to";
                          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,$term,'in',$range,$order_by);
		          if (!is_array($marker_rec_list))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #40: $date<br>\n";
			      echo "Error in call to tableQuery from marker_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')
			    {
			      echo "Your search of the Pedigree Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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 if (sizeof(marker_rec_list) == '0')
                          $final_function_call   = 'tableQuery';
                          $final_table_name      = 'marker_table';
                          $final_field_list      = $field_list_array;
			  $final_term            = $term;
			  $final_mode            = 'in';
			  $final_order_by        = $order_by;
                          $last_record_retrieved = $max_records_to_print_per_page;
                        }#end if more than max_records_to_print_per_page
                      else #less than or equal to max_records_to_print_per_page
                        {
                          $marker_multiple_pages = 0;
                          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,$term,'in','all',$order_by);
		          if (!is_array($marker_rec_list))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #41: $date<br>\n";
			      echo "Error in call to tableQuery from marker_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')
			    {
			      echo "Your search of the Pedigree Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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 if (sizeof(marker_rec_list) == '0')
                        }#end if less or equal to 100 markers
		    }#end if sizeof(field_list) == '1'
		  else
		    {
                      $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_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)
				        {
				          $affect_term_array[] = $term[$j];
				          $affect_mode_array[] = $mode[$j];
				        }#end if right place on list
			            }#end if a real mode
			        }#end foreach mode
                            }#end if affection status table field
                          else #pedigree table field
                            {
                              $final_query_field_list[] = $field_list[$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)
				        {
				          $final_query_term_array[] = $term[$j];
				          $final_query_mode_array[] = $mode[$j];
				        }#end if right place on list
			            }#end if a real mode
			        }#end foreach mode
                            }#end else pedigree table field
			}#end build search query

                      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 #42: $date<br>\n";
                                      echo "Error in call to distinctTableQuery from marker_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 markers.<br>\n";
			                  echo "Please change your search criteria and try a new search.\n";
                                          echo "<form action=\"marker_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 #43: $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 = distinctCompoundTableQuery('pedigree_table_id','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 #44: $date<br>\n";
                                          echo "Error in call to distinctCompoundTableQuery from marker_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 Pedigree Table did not yield any markers.<br>\n";
			                      echo "Please change your search criteria and try a new search.\n";
                                              echo "<form action=\"marker_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
                                        {
                                          $sub_term = join($rec_list,',');
                                          $ped_table_id_array[] = $sub_term;
                                          unset($sub_term);
                                        }#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);
                              unset($ped_table_id_term);
                            }#end if more than one affection field
                          else #only one affection field
                            {
                              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 #45: $date<br>\n";
                                  echo "Error in call to distinctTableQuery from marker_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 markers.<br>\n";
			              echo "Please change your search criteria and try a new search.\n";
                                      echo "<form action=\"marker_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 #46: $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]);
                                  $ped_table_id_array = distinctCompoundTableQuery('pedigree_table_id','pedigree_affection_status_link_table',$database_id,$field_list,$term_array,$mode_array,'and','all');
                                  if (!is_array($ped_id_array))
                                    {
                                      $date = date('Y-m-d H:i:s');
                                      echo "Error #47: $date<br>\n";
                                      echo "Error in call to distinctCompoundTableQuery from marker_search.php<br>\n";
                                      echo "$ped_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_id_array) == '0')
                                    {
                                      if ($join == 'and')
                                        {
                                          echo "<center>\n";
			                  echo "Your search of the Pedigree Table did not yield any markers.<br>\n";
			                  echo "Please change your search criteria and try a new search.\n";
                                          echo "<form action=\"marker_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
                                    {
                                      $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);
                                      unset($ped_table_id_term);
                                    }#end else have records
                                }#end else have affection status record
                            }#end else have one affection field
                        }#end if have affection status fields

		      $ped_table_id_array = distinctCompoundTableQuery('pedigree_table_id',$table_name,$database_id,$field_list,$term_array,$mode_array,$join,'all');
		      if (!is_array($ped_table_id_array))
			{
			  $date = date('Y-m-d H:i:s');
			  echo "Error #48: $date<br>\n";
			  echo "Error in call to distinctCompoundTableQuery from marker_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 distinctCompoundTableQuery
		      if (sizeof($ped_table_id_array) == '0')
			{
			  echo "Your search of the Pedigree Table did not yield any markers.<br>\n";
			  echo "Please change your search criteria and try a new search.<br>\n";
                          echo "<form action=\"marker_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 if no records
		      $ped_table_id_term = join($ped_table_id_array,',');
                      unset($ped_table_id_array);

		      $field_list_array = array('pedigree_table_id');
		      $rec_list = distinctTableJoin('marker_id','individual_table','genotype_table',$database_id,$field_list_array,$ped_table_id_term,'in','all');
		      if (!is_array($rec_list))
			{
			  $date = date('Y-m-d H:i:s');
			  echo "Error #49: $date<br>\n";
			  echo "Error in call to distinctTableJoin from marker_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;
			}
		      if (sizeof($rec_list) == '0')
			{
			  echo "Your search of the Pedigree Table did not yield any markers.<br>\n";
			  echo "Please change your search criteria and try a new search.<br>\n";
                          echo "<form action=\"marker_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 if no records
		      $marker_id_term = join($rec_list,',');
                      unset($rec_list);

		      $field_list_array = array('marker_id');
                      $num_markers = countTableQuery('marker_table',$database_id,$field_list_array,$marker_id_term,'in');
                      if (!preg_match('/^\d+$/',$num_markers))
                        {
                          $date = date('Y-m-d H:i:s');
                          echo "Error #50: $date<br>\n";
                          echo "Error in call to countTableQuery from marker_search.php<br>\n";
                          echo "$num_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 if error in call to countTableQuery

                      #if ($num_markers > $max_records_to_print)
                      #  {
                      #    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,$marker_id_term,'in','all',$order_by);
                      #    if (!is_array($marker_id_array))
                      #      {
                      #        $date = date('Y-m-d H:i:s');
                      #        echo "Error #51: $date<br>\n";
                      #        echo "Error in call to distinctTableQuery from marker_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
                      #    $marker_id_list = join($marker_id_array,',');
                      #    unset($marker_id_array);

                      #    echo "Your search returned $num_markers markers.<br>\n";
                      #    tooManyMarkers($marker_id_list);
                      #    $ret_val = disconnect();
                      #    exit;
                      #  }#end if too many markers to print

                      if ($num_markers > (5 * $max_records_to_print_per_page))
                        {
                          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,$marker_id_term,'in','all',$order_by);
                          if (!is_array($marker_id_array))
                            {
                              $date = date('Y-m-d H:i:s');
                              echo "Error #52: $date<br>\n";
                              echo "Error in call to distinctTableQuery from marker_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
                          $marker_id_list = join($marker_id_array,',');
                          unset($marker_id_array);

                          moreThanFivePages($marker_id_list);
                          unset($marker_id_list);
                        }#end if more than 5 pages of records

                      if ($num_markers > $max_records_to_print_per_page)
                        {
                          $marker_multiple_pages = 1;
                          $from  = 0;
                          $to    = $max_records_to_print_per_page - 1;
                          $range = "$from"."-"."$to";
                          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,$marker_id_term,'in',$range,$order_by);
		          if (!is_array($marker_rec_list))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #53: $date<br>\n";
			      echo "Error in call to tableQuery from marker_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')
			    {
			      echo "Your search of the Pedigree Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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 if (sizeof(marker_rec_list) == '0')
                          $final_function_call   = 'tableQuery';
			  $final_table_name      = 'marker_table';
			  $final_field_list      = $field_list_array;
			  $final_term            = $marker_id_term;
			  $final_mode            = 'in';
			  $final_order_by        = $order_by;
                          $last_record_retrieved = $max_records_to_print_per_page;
                        }#end if more marks to print than allowable per page
                      else # less than or equal to max allowable per page
                        {
                          $marker_multiple_pages = 0;
                          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,$marker_id_term,'in','all',$order_by);
		          if (!is_array($marker_rec_list))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #54: $date<br>\n";
			      echo "Error in call to tableQuery from marker_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')
			    {
			      echo "Your search of the Pedigree Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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 if (sizeof(marker_rec_list) == '0')
                        }#end else less than or equal to max allowable per 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 #55: $date<br>\n";
                          echo "Error in call to distinctTableJoin from marker_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 markers.<br>\n";
			  echo "Please change your search criteria and try a new search.<br>\n";
                          echo "<form action=\"marker_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 #56: $date<br>\n";
			  echo "Error in call to distinctCompoundTableQuery from marker_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 markers.<br>\n";
			  echo "Please change your search criteria and try a new search.<br>\n";
                          echo "<form action=\"marker_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 = 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 #57: $date<br>\n";
                          echo "Error in call to distinctTableQuery from marker_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 markers.<br>\n";
			  echo "Please change your search criteria and try a new search.<br>\n";
                          echo "<form action=\"marker_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');
                  $marker_id_array = distinctTableJoin('marker_id','individual_table','genotype_table',$database_id,$field_list,$ped_table_id_term,'in','all');
                  if (!is_array($marker_id_array))
                    {
                      $date = date('Y-m-d H:i:s');
                      echo "Error #58: $date<br>\n";
                      echo "Error in call to distinctTableJoin from marker_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 distinctTableJoin
		  if (sizeof($marker_id_array) == '0')
		    {
		      echo "<center>\n";
		      echo "Your search of the Pedigree Group Table did not yield any markers.<br>\n";
		      echo "Please change your search criteria and try a new search.\n";
                      echo "<form action=\"marker_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
                  $marker_id_term = join($marker_id_array,',');
                  unset($marker_id_array);
		    
		  $field_list_array = array('marker_id');
                  $num_markers = countTableQuery('marker_table',$database_id,$field_list_array,$marker_id_term,'in');
                  if (!preg_match('/^\d+$/',$num_markers))
                    {
                      $date = date('Y-m-d H:i:s');
		      echo "Error #59: $date<br>\n";
		      echo "Error in call to countTableQuery from marker_search.php<br>\n";
		      echo "$num_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_markers > $max_records_to_print)
                  #  {
                  #    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,$marker_id_term,'in','all',$order_by);
                  #    if (!is_array($marker_id_array))
                  #      {
                  #        $date = date('Y-m-d H:i:s');
		  #        echo "Error #60: $date<br>\n";
		  #        echo "Error in call to distinctTableQuery from marker_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
                  #    $marker_id_list = join($marker_id_array,',');
                  #    unset($marker_id_array);

                  #    echo "Your search returned $num_markers markers.<br>\n";
                  #    tooManyMarkers($marker_id_list);
                  #    $ret_val = disconnect();
                  #    exit;
                  #  }#end if too many markers to print

                  if ($num_markers > (5 * $max_records_to_print_per_page))
                    {
                      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,$marker_id_term,'in','all',$order_by);
                      if (!is_array($marker_id_array))
                        {
                          $date = date('Y-m-d H:i:s');
		          echo "Error #61: $date<br>\n";
		          echo "Error in call to distinctTableQuery from marker_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
                      $marker_id_list = join($marker_id_array,',');
                      unset($marker_id_array);
                      moreThanFivePages($marker_id_list);
                      unset($marker_id_list);
                    }#end if more than 5 pages of records

                  if ($num_markers > $max_records_to_print_per_page)
                    {
                      $marker_multiple_pages = 1;
                      $from  = 0;
                      $to    = $max_records_to_print_per_page - 1;
                      $range = "$from"."-"."$to";
                      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,$marker_id_term,'in',$range,$order_by);
		      if (!is_array($marker_rec_list))
		        {
                          $date = date('Y-m-d H:i:s');
		          echo "Error #62: $date<br>\n";
		          echo "Error in call to tableQuery from marker_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 error in call to tableQuery
		      if (sizeof($marker_rec_list) == '0')
	                {
		          echo "<center>\n";
		          echo "Your search of the Pedigree Group Table did not yield any markers.<br>\n";
		          echo "Please change your search criteria and try a new search.\n";
                          echo "<form action=\"marker_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
                      $final_function_call   = 'tableQuery';
		      $final_table_name      = 'marker_table';
		      $final_field_list      = $field_list_array;
		      $final_term            = $marker_id_term;
		      $final_mode            = 'in';
		      $final_order_by        = $order_by;
                      $last_record_retrieved = $max_records_to_print_per_page;
                    }#end if more markers than allowable per page
                  else #less than or equal to allowable per page
                    {
                      $marker_multiple_pages = 0;
                      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,$marker_id_term,'in','all',$order_by);
		      if (!is_array($marker_rec_list))
		        {
                          $date = date('Y-m-d H:i:s');
		          echo "Error #63: $date<br>\n";
		          echo "Error in call to distinctTableQuery from marker_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 error in call to tableQuery
		      if (sizeof($marker_rec_list) == '0')
	                {
		          echo "<center>\n";
		          echo "Your search of the Pedigree Group Table did not yield any markers.<br>\n";
		          echo "Please change your search criteria and try a new search.\n";
                          echo "<form action=\"marker_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 less than or equal to allowable per page
		}#end if (table_name == 'pedigree_group_table')

	      elseif ($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 build search query

                      if (preg_match('/_affection_status/',$field_list[0]))
                        {
                          $affection_name = preg_replace('/_affection_status/','',$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 #64: $date<br>\n";
                              echo "Error in call to distinctTableQuery from marker_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')
                            {
                              $date = date('Y-m-d H:i:s');
                              echo "There is no affection status in the database with name $affection_name.  It appears that it got deleted \n";
                              echo "from the database before you submitted your request to search based upon its value.  This message was generated at $date.\n";
                              echo "</form>\n";
                              echo "</body></html>\n";
                              $ret_val = disconnect();
                              exit;
                            }
                          elseif(sizeof($affect_id_array) == '1') {$affect_id = $affect_id_array[0];}
                          else
                            {
                              $date = date('Y-m-d H:i:s');
                              echo "Error #65: $date<br>\n";
                              echo "The user wanted to search for markers based upon individuals' affection status for affection status $affection_name \n";
                              echo "with database id $database_id, but when queried the affection status table with those ids 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,$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 #66: $date<br>\n";
                              echo "Error in call to distinctCompoundTableQuery from marker_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 "Your search of the Individual Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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 if no records
                          $indiv_table_id_term = join($indiv_table_id_array,',');
                          unset($indiv_table_id_array);

                          $field_list = array('individual_table_id');
                          $rec_list = distinctTableQuery('marker_id','genotype_table',$database_id,$field_list,$indiv_table_id_term,'in','all');
                          if (!is_array($rec_list))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #67: $date<br>\n";
			      echo "Error in call to distinctTableQuery from marker_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 "Your search of the Individual Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                               echo "<form action=\"marker_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 if (sizeof(rec_list) == '0')
		          $marker_id_term = join($rec_list,',');
                          unset($rec_list);
                        }#end if affection status field
                      else #individual table field
                        {
		          $rec_list = distinctTableJoin('marker_id',$table_name,'genotype_table',$database_id,$field_list,$search_term,$search_mode,'all');
		          if (!is_array($rec_list))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #68: $date<br>\n";
			      echo "Error in call to distinctTableJoin from marker_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 "Your search of the Individual Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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 if (sizeof(rec_list) == '0')
		          $marker_id_term = join($rec_list,',');
                          unset($rec_list);
                        }#end else individual table field

		      $field_list_array = array('marker_id');
                      $num_markers = countTableQuery('marker_table',$database_id,$field_list_array,$marker_id_term,'in');
                      if (!preg_match('/^\d+$/',$num_markers))
                        {
                          $date = date('Y-m-d H:i:s');
			  echo "Error #69: $date<br>\n";
			  echo "Error in call to countTableQuery from marker_search.php<br>\n";
			  echo "$num_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 if error in call to countTableQuery

                      #if ($num_markers > $max_records_to_print)
                      #  {
                      #    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_table',$database_id,$field_list_array,$marker_id_term,'in','all',$order_by);
                      #    if (!is_array($marker_id_array))
                      #      {
                      #        $date = date('Y-m-d H:i:s');
                      #        echo "Error #70: $date<br>\n";
                      #        echo "Error in call to distinctTableQuery from marker_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_list = join($marker_id_array,',');
                      #    unset($marker_id_array);

                      #    echo "Your search returned $num_markers markers.<br>\n";
                      #    tooManyMarkers($marker_id_list);
                      #    $ret_val = disconnect();
                      #    exit;
                      #  }#end if more markers than max_records_to_print

                      if ($num_markers > (5 * $max_records_to_print_per_page))
                        {
                          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_table',$database_id,$field_list_array,$marker_id_term,'in','all',$order_by);
                          if (!is_array($marker_id_array))
                            {
                              $date = date('Y-m-d H:i:s');
                              echo "Error #71: $date<br>\n";
                              echo "Error in call to distinctTableQuery from marker_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_list = join($marker_id_array,',');
                          unset($marker_id_array);
                          moreThanFivePages($marker_id_list);
                          unset($marker_id_list);
                        }#end if more than 5 pages of records

                      if ($num_markers > $max_records_to_print_per_page)
                        {
                          $marker_multiple_pages = 0;
                          $from  = 0;
                          $to    = $max_records_to_print_per_page - 1;
                          $range = "$from"."-"."$to";
                          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,$marker_id_term,'in',$range,$order_by);
		          if (!is_array($marker_rec_list))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #72: $date<br>\n";
			      echo "Error in call to tableQuery from marker_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')
			    {
			      echo "Your search of the Individual Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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 if (sizeof(marker_rec_list) == '0')
                          $final_function_call   = 'tableQuery';
                          $final_table_name      = 'marker_table';
                          $final_field_list      = $field_list_array;
                          $final_term            = $marker_id_term;
                          $final_mode            = 'in';
                          $final_order_by        = $order_by;
                          $last_record_retrieved = $max_records_to_print_per_page;
                        }#end if num_markers > max_records_to_print_per_page
                      else # num_markers <= max_records_to_print_per_page
                        {
                          $marker_multiple_pages = 0;
                          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,$marker_id_term,'in','all',$order_by);
		          if (!is_array($marker_rec_list))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #73: $date<br>\n";
			      echo "Error in call to tableQuery from marker_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')
			    {
			      echo "Your search of the Individual Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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 if (sizeof(marker_rec_list) == '0')
                        }#end else num_markers <= max_records_to_print_per_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('/_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 #individua 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 search query

                      if (sizeof($affect_field_list) > '0')
                      {
                        if (sizeof($affect_field_list) > '1')
                          {
                            $indiv_table_id_array = array();
                            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 #74: $date<br>\n";
                                     echo "Error in call to distinctTableQuery from marker_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 markers.<br>\n";
			                 echo "Please change your search criteria and try a new search.\n";
                                         echo "<form action=\"marker_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 #75: $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 #76: $date<br>\n";
                                         echo "Error in call to distinctCompoundTableQuery from marker_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 markers.<br>\n";
			                     echo "Please change your search criteria and try a new search.\n";
                                             echo "<form action=\"marker_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
                                       {
                                         $sub_term = join($rec_list,',');
                                         $indiv_table_id_array[] = $sub_term;
                                         unset($rec_list);
                                       }#end else have records
                                     unset($rec_list);
                                   }#end else have records
                               }#end foreach search field
                             $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);
                             unset($indiv_table_id_term);
                           }#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 #77: $date<br>\n";
                                 echo "Error in call to distinctTableQuery from marker_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 markers.<br>\n";
			             echo "Please change your search criteria and try a new search.\n";
                                     echo "<form action=\"marker_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 #78: $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 #79: $date<br>\n";
                                     echo "Error in call to distinctCompoundTableQuery from marker_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 markers.<br>\n";
			                 echo "Please change your search criteria and try a new search.\n";
                                         echo "<form action=\"marker_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);
                                     unset($indiv_table_id_term);
                                   }#end else have records
                               }#end else have affection status record
                           }#end else have one affection field
                       }#end if have affection status fields
			   
		      $rec_list = 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($rec_list))
			{
			  $date = date('Y-m-d H:i:s');
			  echo "Error #80: $date<br>\n";
			  echo "Error in call to distinctCompoundTableQuery from marker_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')
			{
			  echo "Your search of the Individual Table did not yield any markers.<br>\n";
			  echo "Please change your search criteria and try a new search.<br>\n";
                          echo "<form action=\"marker_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 if no records
		      $indiv_table_id_term = join($rec_list,',');

		      $field_list_array = array('individual_table_id');
		      $rec_list = distinctTableQuery('marker_id','genotype_table',$database_id,$field_list_array,$indiv_table_id_term,'in','all');
		      if (!is_array($rec_list))
			{
			  $date = date('Y-m-d H:i:s');
			  echo "Error #81: $date<br>\n";
			  echo "Error in call to distinctTableQuery from marker_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 distinctTableQuery
		      if (sizeof($rec_list) == '0')
			{
			  echo "Your search of the Individual Table did not yield any markers.<br>\n";
			  echo "Please change your search criteria and try a new search.<br>\n";
                          echo "<form action=\"marker_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 if no records
		      $marker_id_term = join($rec_list,',');
                      unset($rec_list);

		      $field_list_array = array('marker_id');
                      $num_markers = countTableQuery('marker_table',$database_id,$field_list_array,$marker_id_term,'in');
                      if (!preg_match('/^\d+$/',$num_markers))
                        {
                          $date = date('Y-m-d H:i:s');
			  echo "Error #82: $date<br>\n";
			  echo "Error in call to countTableQuery from marker_search.php<br>\n";
			  echo "$num_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 if error in call to countTableQuery

                      #if ($num_markers > $max_records_to_print)
                      #  {
                      #    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,$marker_id_term,'in','all',$order_by);
                      #    if (!is_array($marker_id_array))
                      #      {
                      #        $date = date('Y-m-d H:i:s');
		#	      echo "Error #83: $date<br>\n";
		#	      echo "Error in call to distinctTableQuery from marker_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_list = join($marker_id_array,',');
                #          unset($marker_id_array);

                #          echo "Your search returned $num_markers markers.<br>\n";
                #          tooManyMarkers($marker_id_list);
                #          $ret_val = disconnect();
                #          exit;
                #        }#end if too many markers

                      if ($num_markers > (5 * $max_records_to_print_per_page))
                        {
                          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,$marker_id_term,'in','all',$order_by);
                          if (!is_array($marker_id_array))
                            {
                              $date = date('Y-m-d H:i:s');
			      echo "Error #84: $date<br>\n";
			      echo "Error in call to distinctTableQuery from marker_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_list = join($marker_id_array,',');
                          unset($marker_id_array);
                          moreThanFivePages($marker_id_list);
                          unset($marker_id_list);
                        }#end if more than half max allowable

                      if ($num_markers > $max_records_to_print_per_page)
                        {
                          $marker_multiple_pages = 1;
                          $from  = 0;
                          $to    = $max_records_to_print_per_page - 1;
                          $range = "$from"."-"."$to";
                          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,$marker_id_term,'in',$range,$order_by);
		          if (!is_array($marker_rec_list))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #85: $date<br>\n";
			      echo "Error in call to tableQuery from marker_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')
			    {
			      echo "Your search of the Individual Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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 if (sizeof(marker_rec_list) == '0')
                          $final_function_call   = 'tableQuery';
                          $final_table_name      = 'marker_table';
                          $final_field_list      = $field_list_array;
                          $final_term            = $marker_id_term;
                          $final_mode            = 'in';
                          $final_order_by        = $order_by;
                          $last_record_retrieved = $max_records_to_print_per_page;
                        }#end if more markers than max_records_to_print_per_page
                      else # less than or equal to max_records_to_print_per_page
                        {
                          $marker_multiple_pages = 0;
                          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,$marker_id_term,'in','all',$order_by);
		          if (!is_array($marker_rec_list))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #86: $date<br>\n";
			      echo "Error in call to tableQuery from marker_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')
			    {
			      echo "Your search of the Individual Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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 if (sizeof(marker_rec_list) == '0')
                        }#end else less than or equal to max_records_to_print_per_page
		    }#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 #87: $date<br>\n";
                          echo "Error in call to distinctTableJoin from marker_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 markers.<br>\n";
			  echo "Please change your search criteria and try a new search.<br>\n";
                          echo "<form action=\"marker_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 = distinctCompoundTableQuery('individual_group_id',$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 #88: $date<br>\n";
			  echo "Error in call to distinctCompoundTableQuery from marker_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')
		        {
			  echo "<center>\n";
			  echo "Your search of the Individual Group Table did not yield any markers.<br>\n";
			  echo "Please change your search criteria and try a new search.<br>\n";
                          echo "<form action=\"marker_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_group_id_term = join($rec_list,',');
                      unset($rec_list);

                      $field_list_array = array('individual_group_id');
                      $indiv_table_id_array = distinctTableQuery('individual_table_id','individual_individual_group_link_table',$database_id,$field_list_array,$indiv_group_id_term,'in','all');
                      if (!is_array($indiv_table_id_array))
                        {
                          $date = date('Y-m-d H:i:s');
			  echo "Error #89: $date<br>\n";
			  echo "Error in call to distinctTableQuery from marker_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 Individual Group Table did not yield any markers.<br>\n";
			  echo "Please change your search criteria and try a new search.<br>\n";
                          echo "<form action=\"marker_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($indiv_table_id_array);
                    }#end else more than one search field

                  $field_list_array = array('individual_table_id');
		  $rec_list = distinctTableQuery('marker_id','genotype_table',$database_id,$field_list_array,$indiv_table_id_term,'in','all');
		  if (!is_array($rec_list))
		    {
                      $date = date('Y-m-d H:i:s');
		      echo "Error #90: $date<br>\n";
		      echo "Error in call to distinctTableQuery from marker_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 distinctTableQuery
		  if (sizeof($rec_list) == '0')
		    {
		      echo "<center>\n";
		      echo "Your search of the Individual Group Table did not yield any markers.<br>\n";
		      echo "Please change your search criteria and try a new search.\n";
                      echo "<form action=\"marker_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
		  $marker_id_term = join($rec_list,',');
                  unset($rec_list);
		    
		  $field_list_array = array('marker_id');
                  $num_markers = countTableQuery('marker_table',$database_id,$field_list_array,$marker_id_term,'in');
                  if (!preg_match('/^\d+$/',$num_markers))
                    {
                      $date = date('Y-m-d H:i:s');
		      echo "Error #91: $date<br>\n";
		      echo "Error in call to countTableQuery from marker_search.php<br>\n";
		      echo "$num_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 if error in call to countTableQuery

                  #if ($num_markers > $max_records_to_print)
                  #  {
                  #    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,$marker_id_term,'in','all',$order_by);
                  #    if (!is_array($marker_id_array))
                  #      {
                  #        $date = date('Y-m-d H:i:s');
		  #        echo "Error #92: $date<br>\n";
		  #        echo "Error in call to distinctTableQuery from marker_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_list = join($marker_id_array,',');
                  #    unset($marker_id_array);

                  #    echo "Your search returned $num_markers markers.<br>\n";
                  #    tooManyMarkers($marker_id_list);
                  #    $ret_val = disconnect();
                  #    exit;
                  #  }#end if too many markers

                  if ($num_markers > (5 * $max_records_to_print_per_page))
                    {
                      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,$marker_id_term,'in','all',$order_by);
                      if (!is_array($marker_id_array))
                        {
                          $date = date('Y-m-d H:i:s');
		          echo "Error #93: $date<br>\n";
		          echo "Error in call to distinctTableQuery from marker_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_list = join($marker_id_array,',');
                      unset($marker_id_array);
                      moreThanFivePages($marker_id_list);
                      unset($marker_id_list);
                    }#end if more than 5 pages of records

                  if ($num_markers > $max_records_to_print_per_page)
                    {
                      $marker_multiple_pages = 1;
                      $from  = 0;
                      $to    = $max_records_to_print_per_page - 1;
                      $range = "$from"."-"."$to";
                      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,$marker_id_term,'in',$range,$order_by);
		      if (!is_array($marker_rec_list))
		        {
		          $date = date('Y-m-d H:i:s');
		          echo "Error #94: $date<br>\n";
		          echo "Error in call to tableQuery from marker_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')
		        {
		          echo "Your search of the Individual Group Table did not yield any markers.<br>\n";
		          echo "Please change your search criteria and try a new search.<br>\n";
                          echo "<form action=\"marker_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 if (sizeof(marker_rec_list) == '0')
                      $final_function_call   = 'tableQuery';
                      $final_table_name      = 'marker_table';
                      $final_field_list      = $field_list_array;
                      $final_term            = $marker_id_term;
                      $final_mode            = 'in';
                      $final_order_by        = $order_by;
                      $last_record_retrieved = $max_records_to_print_per_page;
                    }#end if more markers than max_records_to_print_per_page
                  else # less than or equal to max_records_to_print_per_page
                    {
                      $marker_multiple_pages = 0;
                      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,$marker_id_term,'in','all',$order_by);
		      if (!is_array($marker_rec_list))
		        {
		          $date = date('Y-m-d H:i:s');
		          echo "Error #95: $date<br>\n";
		          echo "Error in call to tableQuery from marker_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')
		        {
		          echo "Your search of the Individual Group Table did not yield any markers.<br>\n";
		          echo "Please change your search criteria and try a new search.<br>\n";
                          echo "<form action=\"marker_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 if (sizeof(marker_rec_list) == '0')
                    }#end else less than or equal to max_records_to_print_per_page
		}#end if (table_name == 'individual_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 build search query

                      $num_markers = countTableJoin($table_name,'marker_table',$database_id,$field_list,$search_term,$search_mode);
                      if (!preg_match('/^\d+$/',$num_markers))
                        {
			  $date = date('Y-m-d H:i:s');
			  echo "Error #96: $date<br>\n";
			  echo "Error in call to countTableJoin from marker_search.php<br>\n";
			  echo "$num_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 if error in call to countTableJoin

                      #if ($num_markers > $max_records_to_print)
                      #  {
                      #    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 = distinctTableJoin('marker_id',$table_name,'marker_table',$database_id,$field_list,$search_term,$search_mode,'all',$order_by);
		      #    if (!is_array($marker_rec_list))
		#	    {
		#	      $date = date('Y-m-d H:i:s');
		#	      echo "Error #97: $date<br>\n";
		#	      echo "Error in call to distinctTableJoin from marker_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 distinctTableJoin
                #          $marker_id_list = join($marker_id_array,',');
                #          unset($marker_id_array);

                #          echo "Your search returned $num_markers markers.<br>\n";
                #          tooManyMarkers($marker_id_list);
                #          $ret_val = disconnect();
                #          exit;
                #        }#end if num_markers > max_records_to_print

                      if ($num_markers > (5 * $max_records_to_print_per_page))
                        {
                          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 = distinctTableJoin('marker_id',$table_name,'marker_table',$database_id,$field_list,$search_term,$search_mode,'all',$order_by);
		          if (!is_array($marker_rec_list))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #98: $date<br>\n";
			      echo "Error in call to distinctTableJoin from marker_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 distinctTableJoin
                          $marker_id_list = join($marker_id_array,',');
                          unset($marker_id_array);
                          moreThanFivePages($marker_id_list);
                          unset($marker_id_list);
                        }#end if more than 5 pages of records

                      if ($num_markers > $max_records_to_print_per_page)
                        {
                          $marker_multiple_pages = 1;
                          $from  = 0;
                          $to    = $max_records_to_print_per_page - 1;
                          $range = "$from"."-"."$to";
                          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 = tableJoin($table_name,'marker_table',$database_id,$field_list,$search_term,$search_mode,$range,$order_by);
		          if (!is_array($marker_rec_list))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #99: $date<br>\n";
			      echo "Error in call to tableJoin from marker_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')
			    {
			      echo "Your search of the Gene Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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 if (sizeof(marker_rec_list) == '0')
                          $final_function_call   = 'tableJoin';
                          $final_table_name      = array($table_name,'marker_table');
                          $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 num_markers > max_records_to_print_per_page
                      else #num_markers less than or equal to max_records_to_print_per_page
                        {
                          $marker_multiple_pages = 0;
                          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 = tableJoin($table_name,'marker_table',$database_id,$field_list,$search_term,$search_mode,'all',$order_by);
		          if (!is_array($marker_rec_list))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #100: $date<br>\n";
			      echo "Error in call to tableJoin from marker_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')
			    {
			      echo "Your search of the Gene Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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 if (sizeof(marker_rec_list) == '0')
                        }#end else num_markers less than or equal to max allowable
		    }#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 query

		      $rec_list = distinctCompoundTableQuery('gene_id',$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 #101: $date<br>\n";
			  echo "Error in call to distinctCompoundTableQuery from marker_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')
			{
			  echo "Your search of the Gene Table did not yield any markers.<br>\n";
			  echo "Please change your search criteria and try a new search.<br>\n";
                          echo "<form action=\"marker_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 if no records
		      $gene_id_term = join($rec_list,',');
                      unset($rec_list);

		      $field_list_array = array('gene_id');
                      $num_markers = countTableQuery('marker_table',$databse_id,$field_list_array,$gene_id_term,'in');
                      if (!preg_match('/^\d+$/',$num_markers))
                        {
                          $date = date('Y-m-d H:i:s');
			  echo "Error #102: $date<br>\n";
			  echo "Error in call to countTableQuery from marker_search.php<br>\n";
			  echo "$num_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 if error in call to countTableQuery

                      #if ($num_markers > $max_records_to_print)
                      #  {
                      #    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,$gene_id_term,'in','all',$order_by);
		      #    if (!is_array($marker_id_array))
		#	    {
		#	      $date = date('Y-m-d H:i:s');
		#	      echo "Error #103: $date<br>\n";
		#	      echo "Error in call to distintTableQuery from marker_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(marker_id_array))
                #          $marker_id_list = join($marker_id_array,',');
                #          unset($marker_id_array);

		#          echo "Your search returned $num_markers markers.<br>\n";
                #          tooManyMarkers($marker_id_list);
                #          $ret_val = disconnect();
                #          exit;
                #        }#end if num_markers > than max allowable

                      if ($num_markers > (5 * $max_records_to_print_per_page))
                        {
                          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,$gene_id_term,'in','all',$order_by);
		          if (!is_array($marker_id_array))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #104: $date<br>\n";
			      echo "Error in call to distinctTableQuery from marker_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(marker_id_array))
                          $marker_id_list = join($marker_id_array,',');
                          unset($marker_id_array);
                          moreThanFivePages($marker_id_list);
                          unset($marker_id_list);
                        }#end if more than 5 pages of records

                      if ($num_markers > $max_records_to_print_per_page)
                        {
                          $marker_multiple_pages = 1;
                          $from  = 0;
                          $to    = $max_records_to_print_per_page - 1;
                          $range = "$from"."-"."$to";
                          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,$gene_id_term,'in',$range,$order_by);
		          if (!is_array($marker_rec_list))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #105: $date<br>\n";
			      echo "Error in call to tableQuery from marker_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')
			    {
			      echo "Your search of the Gene Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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 if (sizeof(marker_rec_list) == '0')
                          $final_function_call   = 'tableQuery';
                          $final_table_name      = 'marker_table';
                          $final_field_list      = $field_list_array;
                          $final_term            = $gene_id_term;
                          $final_mode            = 'in';
                          $final_order_by        = $order_by;
                          $last_record_retrieved = $max_records_to_print_per_page;
                        }#end if num_markers > than max to print per page
                      else #num_markers <= max to print per page
                        {
                          $marker_multiple_pages = 0;
                          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,$gene_id_term,'in','all',$order_by);
		          if (!is_array($marker_rec_list))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #106: $date<br>\n";
			      echo "Error in call to tableQuery from marker_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')
			    {
			      echo "Your search of the Gene Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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 if (sizeof(marker_rec_list) == '0')
                        }#end else num_markers <= max to print per page
		    }#end else sizeof(field_list) > '1'
		}#end if (table_name == 'gene_table')

	      elseif ($table_name == 'genotype_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 build search query

		      if (($field_list[0] == 'individual_id') or ($field_list[0] == 'pedigree_id'))
			{
			  $rec_list = distinctTableJoin('marker_id','individual_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 #107: $date<br>\n";
			      echo "Error in call to distinctTableJoin from marker_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 "Your search of the Genotype Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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 if no records
			  $marker_id_term = join($rec_list,',');
                          unset($rec_list);
			}#end if individual_table field
		      elseif (($field_list[0] == 'marker_name') or ($field_list[0] == 'chromosome'))
			{
			  $rec_list = distinctTableJoin('marker_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 #108: $date<br>\n";
			      echo "Error in call to distinctTableJoin from marker_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 "Your search of the Genotype Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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 if no records
			  $marker_id_term = join($rec_list,',');
                          unset($rec_list);
			}#end if marker_table field
		      elseif (($field_list[0] == 'allele_1_code') or ($field_list[0] == 'allele_2_code'))
			{
			  $field_list_array = array('allele_code');
			  $rec_list = distinctTableQuery('allele_id','allele_table',$database_id,$field_list_array,$search_term,$search_mode,'all');
			  if (!is_array($rec_list))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #109: $date<br>\n";
			      echo "Error in call to distincTableQuery from marker_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 distinctTableQuery
			  if (sizeof($rec_list) == '0')
			    {
			      echo "Your search of the Genotype Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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 if no records
			  $allele_id_term = join($rec_list,',');
                          unset($rec_list);

			  $field_list_array = array('allele_1_id','allele_2_id');
			  $rec_list = distinctTableQuery('marker_id',$table_name,$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 #110: $date<br>\n";
			      echo "Error in call to distincTableQuery from marker_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 distinctTableQuery
			  if (sizeof($rec_list) == '0')
			    {
			      echo "Your search of the Genotype Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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 if no records
			  $marker_id_term = join($rec_list,',');
                          unset($rec_list);
			}#end if allele_table field
		      else #genotype_table field
			{
			  $rec_list = distincTableQuery('marker_id',$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 #111: $date<br>\n";
			      echo "Error in call to distincTableQuery from marker_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 distinctTableQuery
			  if (sizeof($rec_list) == '0')
			    {
			      echo "Your search of the Genotype Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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 if no records
			  $marker_id_term = join($rec_list,',');
                          unset($rec_list);
			}#end else genotype_table field

		      $field_list_array = array('marker_id');
                      $num_markers = countTableQuery('marker_table',$database_id,$field_list_array,$marker_id_term,'in');
                      if (!preg_match('/^\d+$/',$num_markers))
                        {
                          $date = date('Y-m-d H:i:s');
			  echo "Error #112: $date<br>\n";
			  echo "Error in call to countTableQuery from marker_search.php<br>\n";
			  echo "$num_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 if error in call to countTableQuery

                      if ($num_markers > (5 * $max_records_to_print_per_page))
                        {
                          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,$marker_id_term,'in','all',$order_by);
		          if (!is_array($marker_id_array))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #113: $date<br>\n";
			      echo "Error in call to distinctTableQuery from marker_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(marker_id_array))
                          $marker_id_list = join($marker_id_array,',');
                          unset($marker_id_array);
                          moreThanFivePages($marker_id_list);
                          unset($marker_id_list);
                        }#end if num_markers > half max records to print

                      if ($num_markers > $max_records_to_print_per_page)
                        {
                          $marker_multiple_pages = 1;
                          $from  = 0;
                          $to    = $max_records_to_print_per_page - 1;
                          $range = "$from"."-"."$to";
                          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,$marker_id_term,'in',$range,$order_by);
		          if (!is_array($marker_rec_list))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #114: $date<br>\n";
			      echo "Error in call to tableQuery from marker_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')
			    {
			      echo "Your search of the Genotype Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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 if (sizeof(marker_rec_list) == '0')
                          $final_function_call   = 'tableQuery';
                          $final_table_name      = 'marker_table';
                          $final_field_list      = $field_list_array;
                          $final_term            = $marker_id_term;
                          $final_mode            = 'in';
                          $final_order_by        = $order_by;
                          $last_record_retrieved = $max_records_to_print_per_page;
                        }#end if num_markers > max records to print per page
                      else #num_markers <= max_records_to_print_per_page
                        {
                          $marker_multiple_pages = 0;
                          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,$marker_id_term,'in','all',$order_by);
		          if (!is_array($marker_rec_list))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #115: $date<br>\n";
			      echo "Error in call to tableQuery from marker_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')
			    {
			      echo "Your search of the Genotype Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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 if (sizeof(marker_rec_list) == '0')
                        }#end else num_markers <= max_records_to_print_per_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
			    }#end if individual_table field
			  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
			    }#end if marker_table field
			  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
			    }#end if allele_table field
			  else #genotype_table field
			    {
			      $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 if genotype_table field
			}#end build search queries

		      if (sizeof($individual_table_field_list) > '0')
			{
			  if (sizeof($individual_table_field_list) > '1')
			    {
			      $rec_list = 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($rec_list))
				{
				  $date = date('Y-m-d H:i:s');
				  echo "Error #116: $date<br>\n";
				  echo "Error in call to compoundTableQuery from marker_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')
				{
				  $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 if have records
			      else #don't have records
                                {
                                  if ($join == 'and')
                                    {
                                      echo "Your search of the Genotype Table did not yield any markers.<br>\n";
			              echo "Please change your search criteria and try a new search.<br>\n";
                                      echo "<form action=\"marker_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 if join == and
                                }#end else don't have records
			    }#end if sizeof(field_list) > '1'
                          else #sizeof(field_list) == '1'
                            {
                              $rec_list = 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($rec_list))
                                {
                                  $date = date('Y-m-d H:i:s');
                                  echo "Error #117: $date<br>\n";
                                  echo "Error in call to distinctTableQuery from marker_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 callt o distinctTableQuery
                              if (sizeof($rec_list) > '0')
                                {
                                  $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 if have records
                              else #don't have records
			        {
				  if ($join == 'and')
				    {
				      echo "Your search of the Genotype Table did not yield any markers.<br>\n";
			              echo "Please change your search criteria and try a new search.<br>\n";
                                      echo "<form action=\"marker_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 if join == and
                                }#end else don't have records
                            }#end if only have one field
                        }#end if have individual_table_fields

                      if (sizeof($marker_table_field_list) > '0')
                        {
                          if (sizeof($marker_table_field_list) > 1)
                            {
                              $rec_list = distinctCompoundTableQuery('marker_id','marker_table',$database_id,$marker_table_field_list,$marker_table_term_array,$marker_table_mode_array,$join,'all');
                              if (!is_array($rec_list))
                                {
                                  $date = date('Y-m-d H:i:s');
                                  echo "Error #118: $date<br>\n";
                                  echo "Error in call to distinctCompoundTableQuery from marker_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
                            }#end if more than one marker table field
                          else #only one marker table field
                            {
                              $rec_list = 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($rec_list))
                                {
                                  $date = date('Y-m-d H:i:s');
                                  echo "Error #119: $date<br>\n";
                                  echo "Error in call to distinctTableQuery from marker_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 distinctTableQuery
                            }#end else only one marker table field
                          if (sizeof($rec_list) > '0')
                            {
                              $marker_id_term = join($rec_list,',');
                              $final_query_field_list[] = 'marker_id';
                              $final_query_term_array[] = $marker_id_term;
                              $final_query_mode_array[] = 'in';
                              unset($rec_list);
                            }#end if have records
                          else #don't have records
			    {
			      if ($join == 'and')
				{
				  echo "Your search of the Genotype Table did not yield any markers.<br>\n";
				  echo "Please change your search criteria and try a new search.<br>\n";
                                  echo "<form action=\"marker_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 if join == 'and'
			    }#end else don't have records
                        }#end if have marker_table field

                      if (sizeof($allele_table_field_list) > '0')
                        {
                          if (sizeof($allele_table_field_list) > '1')
                            {
                              $rec_list = distinctCompoundTableQuery('allele_id','allele_table',$database_id,$allele_table_field_list,$allele_table_term_array,$allele_table_mode_array,'or','all');
                              if (!is_array($rec_list))
                                {
                                  $date = date('Y-m-d H:i:s');
                                  echo "Error #120: $date<br>\n";
                                  echo "Error in call to distinctCompoundTableQuery from marker_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')
                                {
                                  $allele_id_term = join($rec_list,',');

                                  if ($join == 'and')
                                    {
                                      $field_list_array = array('allele_1_id','allele_2_id');
                                      $term_array = array($allele_id_term,$allele_id_term);
                                      $mode_array = array('in','in');
                                      $rec_list = distinctCompoundTableQuery('genotype_id','genotype_table',$database_id,$field_list_array,$term_array,$mode_array,'and','all');
                                      if (!is_array($rec_list))
                                        {
                                          $date = date('Y-m-d H:i:s');
                                          echo "Error #121: $date<br>\n";
                                          echo "Error in call to compoundTableQuery from marker_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 "Your search of the Genotype Table did not yield any markers.<br>\n";
				          echo "Please change your search criteria and try a new search.<br>\n";
                                          echo "<form action=\"marker_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 if no records
                                      $genotype_id_term = join($rec_list,',');
                                      $final_query_field_list[] = 'genotype_id';
                                      $final_query_term_array[] = $genotype_id_term;
                                      $final_query_mode_array[] = 'in';
                                      unset($rec_list);
                                    }#end if join == and
                                  else #join == or
                                    {
                                      $field_list_array = array('allele_1_id','allele_2_id');
                                      $rec_list = distinctTableQuery('genotype_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 #122: $date<br>\n";
                                          echo "Error in call to distinctTableQuery from marker_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 distinctTableQuery
                                      if (sizeof($rec_list) > '0')
                                        {
                                          $genotype_id_term = join($rec_list,',');
                                          $final_query_field_list[] = 'genotype_id';
                                          $final_query_term_array[] = $genotype_id_term;
                                          $final_query_term_array[] = 'in';
                                          unset($rec_list);
                                        }
                                    }#end else join == or
                                }#end if have records
                              else #don't have records
			        {
				  if ($join == 'and')
				    {
				      echo "Your search of the Genotype Table did not yield any markers.<br>\n";
				      echo "Please change your search criteria and try a new search.<br>\n";
                                      echo "<form action=\"marker_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 if join == 'and'
				}#end else don't have records
			    }#end if sizeof(allele_table_field_list) > '1'
			  else #sizeof(allele_table_field_list) == '1'
			    {
			      $rec_list = 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($rec_list))
                                {
                                  $date = date('Y-m-d H:i:s');
                                  echo "Error #123: $date<br>\n";
                                  echo "Error in call to distinctTableQuery from marker_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 distinctTableQuery
			      if (sizeof($rec_list) > '0')
				{
				  $allele_id_term = join($rec_list,',');
				  $field_list_array = array('allele_1_id','allele_2_id');
				  $rec_list = distinctTableQuery('genotype_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 #124: $date<br>\n";
				      echo "Error in call to distinctTableQuery from marker_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 distinctTableQuery
				  if (sizeof($rec_list) > '0')
				    {
				      $genotype_id_term = join($rec_list,',');
				      $final_query_field_list[] = 'genotype_id';
				      $final_query_term_array[] = $genotype_id_term;
				      $final_query_mode_array[] = 'in';
                                      unset($rec_list);
				    }#end if sizeof(rec_list) > '0'
				  else #no records
				    {
				      if ($join == 'and')
					{
					  echo "Your search of the Genotype Table did not yield any markers.<br>\n";
					  echo "Please change your search criteria and try a new search.<br>\n";
                                          echo "<form action=\"marker_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 if join == 'and'
                                    }#end else sizeof(rec_list) == '0'
				}#end if sizeof(rec_list) > '0'
                            }#end else sizeof(allele_table_field_list) == '1'
                        }#end if have allele_table_fields

		      $rec_list = distinctCompoundTableQuery('marker_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 #125: $date<br>\n";
			  echo "Error in call to compoundTableQuery from marker_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;
			}
		      if (sizeof($rec_list) == '0')
			{
			  echo "Your search of the Genotype Table did not yield any markers.<br>\n";
			  echo "Please change your search criteria and try a new search.<br>\n";
                          echo "<form action=\"marker_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 if no records
		      $marker_id_term = join($rec_list,',');
                      unset($rec_list);
		      
		      $field_list_array = array('marker_id');
                      $num_markers = countTableQuery('marker_table',$database_id,$field_list_array,$marker_id_term,'in');
                      if (!preg_match('/^\d+$/',$num_markers))
                        {
                          $date = date('Y-m-d H:i:s');
			  echo "Error #126: $date<br>\n";
			  echo "Error in call to countTableQuery from marker_search.php<br>\n";
			  echo "$num_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 if error in call to countTableQuery

                      #if ($num_markers > $max_records_to_print)
                      #  {
                      #    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,$marker_id_term,'in','all',$order_by);
		      #    if (!is_array($marker_id_array))
		#	    {
		#	      $date = date('Y-m-d H:i:s');
		#	      echo "Error #127: $date<br>\n";
		#	      echo "Error in call to distinctTableQuery from marker_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(marker_id_array))
                #          $marker_id_list = join($marker_id_array,',');
                #          unset($marker_id_array);

                #          echo "Your search returned $num_markers markers.<br>\n";
                #          tooManyMarkers($marker_id_list);
                #          $ret_val = disconnect();
                #          exit;
                #        }#end if num_markers > max_records to print

                      if ($num_markers > (5 * $max_records_to_print_per_page))
                        {
                          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,$marker_id_term,'in','all',$order_by);
		          if (!is_array($marker_id_array))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #128: $date<br>\n";
			      echo "Error in call to distinctTableQuery from marker_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(marker_id_array))
                          $marker_id_list = join($marker_id_array,',');
                          moreThanFivePages($marker_id_list);
                          unset($marker_id_array);
                          unset($marker_id_list);
                        }#end if more than 5 pages of records

                      if ($num_markers > $max_records_to_print_per_page)
                        {
                          $marker_multiple_pages = 1;
                          $from  = 0;
                          $to    = $max_records_to_print_per_page - 1;
                          $range = "$from"."-"."$to";
                          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,$marker_id_term,'in',$range,$order_by);
		          if (!is_array($marker_rec_list))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #129: $date<br>\n";
			      echo "Error in call to tableQuery from marker_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')
			    {
			      echo "Your search of the Genotype Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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 if (sizeof(marker_rec_list) == '0')
                          $final_function_call    = 'tableQuery';
                          $final_table_name       = 'marker_table';
                          $final_field_list       = $field_list_array;
                          $final_term             = $marker_id_term;
                          $final_mode             = 'in';
                          $final_order_by         = $order_by;
                          $last_record_retrieved = $max_records_to_print_per_page;
                        }#end if num_markers > max_records_to_print_per_page
                      else #num_markers <= max_records_to_print_per_page
                        {
                          $marker_multiple_pages = 0;
                          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,$marker_id_term,'in','all',$order_by);
		          if (!is_array($marker_rec_list))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #130: $date<br>\n";
			      echo "Error in call to tableQuery from marker_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')
			    {
			      echo "Your search of the Genotype Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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 if (sizeof(marker_rec_list) == '0')
                        }#end else num_markers <= max_records_to_print_per_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];
			    }
			}

		      if ($field_list[0] == 'marker_name')
			{
			  $rec_list = distinctTableJoin('marker_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 #131: $date<br>\n";
			      echo "Error in call to distinctTableJoin from marker_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 "Your search of the Allele Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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 if no records
			  $marker_id_term = join($rec_list,',');
			}#end if marker_table field
		      else #allele_table field
			{
			  $rec_list = distinctTableQuery('marker_id',$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 #132: $date<br>\n";
			      echo "Error in call to distinctTableQuery from marker_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 "Your search of the Allele Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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 if (sizeof(rec_list) == '0')
		          $marker_id_term = join($rec_list,',');
			}#end else allele_table field

		      $field_list_array = array('marker_id');
                      $num_markers = countTableQuery('marker_table',$database_id,$field_list_array,$marker_id_term,'in');
                      if (!preg_match('/^\d+$/',$num_markers))
                        {
			  $date = date('Y-m-d H:i:s');
			  echo "Error #133: $date<br>\n";
			  echo "Error in call to countTableQuery from marker_search.php<br>\n";
			  echo "$num_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 if error in call to countTableQuery

                      #if ($num_markers > $max_records_to_print)
                      #  {
                      #    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,$marker_id_term,'in','all',$order_by);
		      #    if (!is_array($marker_id_array))
		#	    {
		#	      $date = date('Y-m-d H:i:s');
		#	      echo "Error #134: $date<br>\n";
		#	      echo "Error in call to distinctTableQuery from marker_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_term = join($marker_id_array,',');
                #          unset($marker_id_array);

                #          echo "Your search returned $num_markers markers.<br>\n";
                #          tooManyMarkers($marker_id_term);
                #          $ret_val = disconnect();
                #          exit;
                #        }#end if too many records to print

                      if ($num_markers > (5 * $max_records_to_print_per_page))
                        {
                          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,$marker_id_term,'in','all',$order_by);
		          if (!is_array($marker_id_array))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #135: $date<br>\n";
			      echo "Error in call to distinctTableQuery from marker_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_term = join($marker_id_array,',');
                          unset($marker_id_array);
                          moreThanFivePages($marker_id_term);
                          unset($marker_id_term);
                        }#end if more than 5 pages of records

                      if ($num_markers > $max_records_to_print_per_page)
                        {
                          $marker_multiple_pages = 1;
                          $from  = 0;
                          $to    = $max_records_to_print_per_page - 1;
                          $range = "$from"."-"."$to";
                          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,$marker_id_term,'in',$range,$order_by);
		          if (!is_array($marker_rec_list))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #136: $date<br>\n";
			      echo "Error in call to tableQuery from marker_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')
			    {
			      echo "Your search of the Allele Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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 if (sizeof(marker_rec_list) == '0')
                          $final_function_call    = 'tableQuery';
                          $final_table_name       = 'marker_table';
                          $final_field_list       = $field_list_array;
                          $final_term             = $marker_id_term;
                          $final_mode             = 'in';
                          $final_order_by         = $order_by;
                          $last_record_retrieved = $max_records_to_print_per_page;
                        }#end if more markers than should be printed per page
                      else #num markers <= markers to be printed per page
                        {
                          $marker_multiple_pages = 0;
                          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,$marker_id_term,'in','all',$order_by);
		          if (!is_array($marker_rec_list))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #137: $date<br>\n";
			      echo "Error in call to tableQuery from marker_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')
			    {
			      echo "Your search of the Allele Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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 if (sizeof(marker_rec_list) == '0')
                        }#end else num markers <= marker to be printed per 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 = $term[$j];
					}#end if right place on list
				    }#end if real mode
				}#end foreach mode
			    }#end if marker_table field
			  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 else allele_table field
			}#end build search queries

		      if (sizeof($marker_table_field_list) > '0')
			{
			  $rec_list = distinctTableQuery('marker_id','marker_table',$database_id,$marker_table_field_list,$marker_table_search_term,$marker_table_search_mode,'all');
			  if (!is_array($rec_list))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #138: $date<br>\n";
			      echo "Error in call to distinctTableQuery from marker_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 distinctTableQuery
			  if (sizeof($rec_list) > '0')
			    {
			      $marker_id_term = join($rec_list,',');
			      $final_query_field_list[] = 'marker_id';
			      $final_query_term_array[] = $marker_id_term;
			      $final_query_mode_array[] = 'in';
                              unset($rec_list);
                              unset($marker_id_term);
			    }#end if have records
			  else #no records
			    {
			      if ($join == 'and')
				{
				  echo "Your search of the Allele Table did not yield any markers.<br>\n";
				  echo "Please change your search criteria and try a new search.<br>\n";
                                  echo "<form action=\"marker_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 if join == and
			    }#end else have no records
			}#end if have marker_table_fields

		      $rec_list = distinctCompoundTableQuery('marker_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 marker_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')
			{
			  echo "Your search of the Allele Table did not yield any markers.<br>\n";
			  echo "Please change your search criteria and try a new search.<br>\n";
                          echo "<form action=\"marker_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 if no records
		      $marker_id_term = join($rec_list,',');
                      unset($rec_list);

		      $field_list_array = array('marker_id');
                      $num_markers = countTableQuery('marker_table',$database_id,$field_list_array,$marker_id_term,'in');
                      if (!preg_match('/^\d+$/',$num_markers))
                        {
			  $date = date('Y-m-d H:i:s');
			  echo "Error #140: $date<br>\n";
			  echo "Error in call to countTableQuery from marker_search.php<br>\n";
			  echo "$num_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 if error in call to countTableQuery

                      #if ($num_markers > $max_records_to_print)
                      #  {
                      #    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,$marker_id_term,'in','all',$order_by);
		      #    if (!is_array($marker_id_array))
		#	    {
		#	      $date = date('Y-m-d H:i:s');
		#	      echo "Error #141: $date<br>\n";
		#	      echo "Error in call to distinctTableQuery from marker_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 distinctTableQuery
                #          $marker_id_term = join($marker_id_array,',');
                #          unset($marker_id_array);

                #          echo "Your search returned $num_markers markers.<br>\n";
                #          tooManyMarkers($marker_id_term);
                #          $ret_val = disconnect();
                #          exit;
                #        }#end if too many markers to print

                      if ($num_markers > (5 * $max_records_to_print_per_page))
                        {
                          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,$marker_id_term,'in','all',$order_by);
		          if (!is_array($marker_id_array))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #142: $date<br>\n";
			      echo "Error in call to distinctTableQuery from marker_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 distinctTableQuery
                          $marker_id_term = join($marker_id_array,',');
                          unset($marker_id_array);
                          moreThanFivePages($marker_id_term);
                          unset($marker_id_term);
                        }#end if more than 5 pages 

                      if ($num_markers > $max_records_to_print_per_page)
                        {
                          $marker_multiple_pages = 1;
                          $from  = 0;
                          $to    = $max_records_to_print_per_page - 1;
                          $range = "$from"."-"."$to";
                          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,$marker_id_term,'in',$range,$order_by);
		          if (!is_array($marker_rec_list))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #143: $date<br>\n";
			      echo "Error in call to tableQuery from marker_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')
			    {
			      echo "Your search of the Allele Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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 if (sizeof(marker_rec_list) == '0')
                          $final_function_call   = 'tableQuery';
                          $final_table_name      = 'marker_table';
                          $final_field_list      = $field_list_array;
                          $final_term            = $marker_id_term;
                          $final_mode            = 'in';
                          $final_order_by        = $order_by;
                          $last_record_retrieved = $max_records_to_print_per_page;
                        }#end if multiple pages of markers
                      else #only a single page of markers
                        {
                          $marker_multiple_pages = 0;
                          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,$marker_id_term,'in','all',$order_by);
		          if (!is_array($marker_rec_list))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #144: $date<br>\n";
			      echo "Error in call to tableQuery from marker_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')
			    {
			      echo "Your search of the Allele Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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 if (sizeof(marker_rec_list) == '0')
                        }#end else only a single page of markers
		    }#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($field_list);
		      for ($i='0'; $i<$num_of_modes; $i++)
			{
			  if ($mode[$i] != 'Select Type of Search')
			    {
			      $search_term = $term[$i];
			      $search_mode = $mode[$i];
			    }
			}#end foreach mode

                      $indiv_table_id_array = array();
		      $qual_indiv_table_id_array = distinctTableJoin('individual_table_id',$table_name,'qualitative_phenotype_value_table',$database_id,$field_list,$search_term,$search_mode,'all');
		      if (!is_array($qual_indiv_table_id_array))
			{
			  $date = date('Y-m-d H:i:s');
			  echo "Error #145: $date<br>\n";
			  echo "Error in call to distinctTableJoin from marker_search.php<br>\n";
			  echo "$qual_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 in call to distinctTableJoin
                      if (sizeof($qual_indiv_table_id_array) > '0')
                        {
                          $qual_indiv_table_id_term = join($qual_indiv_table_id_array,',');
                          $indiv_table_id_array[] = $qual_indiv_table_id_term;
                          unset($qual_indiv_table_id_term);
                        }
                      unset($qual_indiv_table_id_array);

                      $quant_indiv_table_id_array = distinctTableJoin('individual_table_id',$table_name,'quantitative_phenotype_value_table',$database_id,$field_list,$search_term,$search_mode,'all');
		      if (!is_array($quant_indiv_table_id_array))
			{
			  $date = date('Y-m-d H:i:s');
			  echo "Error #146: $date<br>\n";
			  echo "Error in call to distinctTableJoin from marker_search.php<br>\n";
			  echo "$quant_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 in call to distinctTableJoin
                      if (sizeof($quant_indiv_table_id_array) > '0')
                        {
                          $quant_indiv_table_id_term = join($quant_indiv_table_id_array,',');
                          $indiv_table_id_array[] = $quant_indiv_table_id_term;
                          unset($quant_indiv_table_id_term);
                        }
                      unset($quant_indiv_table_id_array);

		      if (sizeof($indiv_table_id_array) == '0')
			{
			  echo "Your search of the Phenotype Table did not yield any markers.<br>\n";
			  echo "Please change your search criteria and try a new search.<br>\n";
                          echo "<form action=\"marker_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 if (sizeof(rec_list) == '0')
		      $individual_table_id_term = join($indiv_table_id_array,',');
                      unset($indiv_table_id_array);
		    }#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 a real mode
			    }#end foreach mode
			}#end build search query

		      $rec_list = distinctCompoundTableQuery('phenotype_id',$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 #147: $date<br>\n";
			  echo "Error in call to distinctCompoundTableQuery from marker_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')
			{
			  echo "Your search of the Phenotype Table did not yield any markers.<br>\n";
			  echo "Please change your search criteria and try a new search.<br>\n";
                          echo "<form action=\"marker_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;
			}
		      $phenotype_id_term = join($rec_list,',');
                      unset($rec_list);

		      $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 #148: $date<br>\n";
			  echo "Error in call to distinctTableQuery from marker_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 #149: $date<br>\n";
			  echo "Error in call to distinctTableQuery from marker_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 "Your search of the Phenotype Table did not yield any markers.<br>\n";
			  echo "Please change your search criteria and try a new search.<br>\n";
                          echo "<form action=\"marker_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;
			}
		      if ((sizeof($rec_list_1) > '0') and (sizeof($rec_list_2) == '0'))
                        {$individual_table_id_term = join($rec_list_1,',');}
                      elseif ((sizeof($rec_list_1) == '0') and (sizeof($rec_list_2) > '0'))
                        {$individual_table_id_term = join($rec_list_2,',');}
                      else
                        {
                          $individual_table_id_term = join($rec_list_1,',');
                          $individual_table_id_term.= ",";
                          $individual_table_id_term.= join($rec_list_2,',');
                        }#end both qualitative and quantitative phenotypes
                      unset($rec_list_1,$rec_list_2);
		    }#end else sizeof(field_list) > '1'

		  $field_list_array = array('individual_table_id');
		  $rec_list = distinctTableQuery('marker_id','genotype_table',$database_id,$field_list_array,$individual_table_id_term,'in','all');
		  if (!is_array($rec_list))
		    {
		      $date = date('Y-m-d H:i:s');
		      echo "Error #150: $date<br>\n";
		      echo "Error in call to distinctTableQuery from marker_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 "Your search of the Phenotype Table did not yield any markers.<br>\n";
		      echo "Please change your search criteria and try a new search.<br>\n";
                      echo "<form action=\"marker_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 if (sizeof(rec_list) == '0')
		  $marker_id_term = join($rec_list,',');
                  unset($rec_list);

		  $field_list_array = array('marker_id');
                  $num_markers = countTableQuery('marker_table',$database_id,$field_list_array,$marker_id_term,'in');
                  if (!preg_match('/^\d+$/',$num_markers))
                    {
		      $date = date('Y-m-d H:i:s');
		      echo "Error #151: $date<br>\n";
		      echo "Error in call to countTableQuery from marker_search.php<br>\n";
		      echo "$num_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 if error in call to countTableQuery

                  #if ($num_markers > $max_records_to_print)
                  #  {
                  #    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,$marker_id_term,'in','all',$order_by);
		  #    if (!is_array($marker_rec_list))
		  #      {
		  #        $date = date('Y-m-d H:i:s');
		  #        echo "Error #152: $date<br>\n";
		  #        echo "Error in call to distinctTableQuery from marker_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_term = join($marker_id_array,',');
                  #    unset($marker_id_array);

                  #    echo "Your search returned $num_markers markers.<br>\n";
                  #    tooManyMarkers($marker_id_term);
                  #    $ret_val = disconnect();
                  #    exit;
                  #  }#end if too many markers to print

                  if ($num_markers > ( 5 * $max_records_to_print_per_page))
                    {
                      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,$marker_id_term,'in','all',$order_by);
		      if (!is_array($marker_rec_list))
		        {
		          $date = date('Y-m-d H:i:s');
		          echo "Error #153: $date<br>\n";
		          echo "Error in call to distinctTableQuery from marker_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_term = join($marker_id_array,',');
                      unset($marker_id_array);
                      moreThanFivePages($marker_id_term);
                      unset($marker_id_term);
                    }#end if more than 5 pages

                  if ($num_markers > $max_records_to_print_per_page)
                    {
                      $marker_multiple_pages = 1;
                      $from  = 0;
                      $to    = $max_records_to_print_per_page - 1;
                      $range = "$from"."-"."$to";
                      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,$marker_id_term,'in',$range,$order_by);
		      if (!is_array($marker_rec_list))
		        {
		          $date = date('Y-m-d H:i:s');
		          echo "Error #154: $date<br>\n";
		          echo "Error in call to tableQuery from marker_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')
		        {
		          echo "Your search of the Phenotype Table did not yield any markers.<br>\n";
		          echo "Please change your search criteria and try a new search.<br>\n";
                          echo "<form action=\"marker_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 if (sizeof(marker_rec_list) == '0')
                      $final_function_call    = 'tableQuery';
                      $final_table_name       = 'marker_table';
                      $final_field_list       = $field_list_array;
                      $final_term             = $marker_id_term;
                      $final_mode             = 'in';
                      $final_order_by         = $order_by;
                      $last_record_retrieved = $max_records_to_print_per_page;
                    }#end if multiple pages of markers
                  else #only a single page of markers
                    {
                      $marker_multiple_pages = 0;
                      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,$marker_id_term,'in','all',$order_by);
		      if (!is_array($marker_rec_list))
		        {
		          $date = date('Y-m-d H:i:s');
		          echo "Error #155: $date<br>\n";
		          echo "Error in call to tableQuery from marker_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')
		        {
		          echo "Your search of the Phenotype Table did not yield any markers.<br>\n";
		          echo "Please change your search criteria and try a new search.<br>\n";
                          echo "<form action=\"marker_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 if (sizeof(marker_rec_list) == '0')
                    }#end else only a single page of markers
		}#end if (table_name == 'phenotpe_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 = $term[$i];
			    }
			}

		      if (($field_list[0] == 'individual_id') or ($field_list[0] == 'pedigree_id'))
			{
			  $rec_list_1 = distinctTableJoin('individual_table_id','individual_table','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 #156: $date<br>\n";
			      echo "Error in call to distinctTableJoin from marker_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','individual_table','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 #157: $date<br>\n";
			      echo "Error in call to distinctTableJoin from marker_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 "Your search of the Phenotype Value Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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;
			    }
                          if ((sizeof($rec_list_1) > '0') and (sizeof($rec_list_2) == '0'))
			    {$individual_table_id_term = join($rec_list_1,',');}
                          elseif ((sizeof($rec_list_1) == '0') and (sizeof($rec_list_2) > '0'))
                            {$individual_table_id_term = join($rec_list_2,',');}
                          else
                            {
                              $individual_table_id_term = join($rec_list_1,',');
                              $individual_table_id_term.= ",";
                              $individual_table_id_term.= join($rec_list_2,',');
                            }
			}#end if individual_table fields
		      elseif (($field_list[0] == 'phenotype_name') or ($field_list[0] == 'type_of_phenotype'))
			{
			  $rec_list_1 = distinctTableJoin('individual_table_id','phenotype_table','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 #158: $date<br>\n";
			      echo "Error in call to distinctTableJoin from marker_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','phenotype_table','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 #159: $date<br>\n";
			      echo "Error in call to distinctTableJoin from marker_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 "Your search of the Phenotype Value Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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;
			    }
                          if ((sizeof($rec_list_1) > '0') and (sizeof($rec_list_2) == '0'))
			    { $individual_table_id_term = join($rec_list_1,',');}
                          elseif ((sizeof($rec_list_1) == '0') and (sizeof($rec_list_2) > '0'))
                            { $individual_table_id_term = join($rec_list_2,',');}
                          else
                            {
                              $individual_table_id_term = join($rec_list_1,',');
                              $individual_table_id_term.= ",";
                              $individual_table_id_term.= join($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,$term,$mode,'all');
			  if (!is_array($rec_list_1))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #160: $date<br>\n";
			      echo "Error in call to distinctTableQuery from marker_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 if error in call to distinctTableQuery

                          $rec_list_2 = distinctTableQuery('individual_table_id','quantitative_phenotype_value_table',$database_id,$field_list,$term,$mode,'all');
			  if (!is_array($rec_list_2))
			    {
			      $date = date('Y-m-d H:i:s');
			      echo "Error #161: $date<br>\n";
			      echo "Error in call to distinctTableQuery from marker_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 if error in call to distinctTableQuery

		          if ((sizeof($rec_list_1) == '0') and (sizeof($rec_list_2) == '0'))
			    {
			      echo "Your search of the Phenotype Value Table did not yield any markers.<br>\n";
			      echo "Please change your search criteria and try a new search.<br>\n";
                              echo "<form action=\"marker_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 if (sizeof(rec_list) == '0')
                          if ((sizeof($rec_list_1) > '0') and (sizeof($rec_list_2) == '0'))
		            { $individual_table_id_term = join($rec_list_1,',');}
                          elseif ((sizeof($rec_list_1) == '0') and (sizeof($rec_list_2) > '0'))
                            { $individual_table_id_term = join($rec_list_2,',');}
                          else
                            {
                              $individual_table_id_term = join($rec_list_1,',');
                              $individual_table_id_term.= ",";
                              $individual_table_id_term.= join($rec_list_2,',');
                            }
			}#end else phenotype_value_table
		    }#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 in right place
				    }#end if real mode
				}#end foreach mode
			    }#end if individual_table fields
			  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 in right place
				    }#end if real mode
				}#end foreach mode
			    }#end if phenotype_table field
			  else #phenotype_value_table field
			    {
			      $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 in right place
				    }#end if real mode
				}#end foreach mode
			    }#end if phenotype_value_table field
			}#end build search queries

		      if (sizeof($individual_table_field_list) > '0')
			{
			  if (sizeof($individual_table_field_list) > '1')
			    {
			      $rec_list = 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($rec_list))
				{
				  $date = date('Y-m-d H:i:s');
				  echo "Error #162: $date<br>\n";
				  echo "Error in call to distinctCompoundTableQuery from marker_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')
				{
				  $individual_table_id_term = join($rec_list,',');
				  $final_query_field_list[] = 'individual_table_id';
				  $final_query_term_array[] = $individual_table_id_term;
				  $final_query_mode_array[] = 'in';
                                  unset($individual_table_id_term);
				}
			      else
				{
				  if ($join == 'and')
				    {
				      echo "Your search of the Phenotype Value Table did not yield any markers.<br>\n";
				      echo "Please change your search criteria and try a new search.<br>\n";
                                      echo "<form action=\"marker_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 if join == and
				}#end else no records
                              unset($rec_list);
			    }#end if sizeof(field_list) > '1'
			  else #sizeof(field_list) == '1'
			    {
			      $rec_list = 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($rec_list))
			        {
				  $date = date('Y-m-d H:i:s');
				  echo "Error #163: $date<br>\n";
				  echo "Error in call to distinctTableQuery from marker_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 distinctTableQuery
			      if (sizeof($rec_list) > '0')
			        {
				  $individual_table_id_term = join($rec_list,',');
				  $final_query_field_list[] = 'individual_table_id';
				  $final_query_term_array[] = $individual_table_id_term;
				  $final_query_mode_array[] = 'in';
                                  unset($individual_table_id_term);
				}
			      else
			        {
				  if ($join == 'and')
				    {
				      echo "Your search of the Phenotype Value Table did not yield any markers.<br>\n";
				      echo "Please change your search criteria and try a new search.<br>\n";
                                      echo "<form action=\"marker_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 if join == and
				}#end else no records
                              unset($rec_list);
			    }#end else sizeof(field_list) == '1'
			}#end if sizeof(individual_table_field_list) > '0'
		      if (sizeof($phenotype_table_field_list) > '0')
			{
                          if (sizeof($phenotype_table_field_list) > '1')
                            {
                              $rec_list = distinctCompoundTableQuery('phenotype_id','phenotype_table',$database_id,$phenotype_table_field_list,$phenotype_table_term_array,$phenotype_table_mode_array,$join,'all');
			      if (!is_array($rec_list))
			        {
			          $date = date('Y-m-d H:i:s');
			          echo "Error #164: $date<br>\n";
			          echo "Error in call to distinctCompoundTableQuery from marker_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')
			        {
			          $phenotype_id_term = join($rec_list,',');
			          $final_query_field_list[] = 'phenotype_id';
			          $final_query_term_array[] = $phenotype_id_term;
			          $final_query_mode_array[] = 'in';
                                  unset($phenotype_id_term);
			        }
			      else
			        {
			          if ($join == 'and')
				    {
				      echo "Your search of the Phenotype Value Table did not yield any markers.<br>\n";
				      echo "Please change your search criteria and try a new search.<br>\n";
                                      echo "<form action=\"marker_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 if join == and
			        }#end else no records
                              unset($rec_list);
                            }#end if more than one phenotype table field
                          else #only a single phenotype table field
                            {
			      $rec_list = distinctTableQuery('phenotype_id','phenotype_table',$database_id,$phenotype_table_field_list,$phenotype_table_term_array[0],$phenotype_table_mode_array[0],'all');
			      if (!is_array($rec_list))
			        {
			          $date = date('Y-m-d H:i:s');
			          echo "Error #165: $date<br>\n";
			          echo "Error in call to distinctTableQuery from marker_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 distinctTableQuery
			      if (sizeof($rec_list) > '0')
			        {
			          $phenotype_id_term = join($rec_list,',');
			          $final_query_field_list[] = 'phenotype_id';
			          $final_query_term_array[] = $phenotype_id_term;
			          $final_query_mode_array[] = 'in';
                                  unset($phenotype_id_term);
			        }
			      else
			        {
			          if ($join == 'and')
				    {
				      echo "Your search of the Phenotype Value Table did not yield any markers.<br>\n";
				      echo "Please change your search criteria and try a new search.<br>\n";
                                      echo "<form action=\"marker_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 if join == and
			        }#end else no records
                              unset($rec_list);
                            }#end else only a single phenotype table field
			}#end if sizeof(phentoype_table_field_list) > '0'

		      $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 #166: $date<br>\n";
			  echo "Error in call to distinctCompoundTableQuery from marker_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 #167: $date<br>\n";
			  echo "Error in call to distinctCompoundTableQuery from marker_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 "Your search of the Phenotype Value Table did not yield any markers.<br>\n";
			  echo "Please change your search criteria and try a new search.<br>\n";
                          echo "<form action=\"marker_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 if no records
                      if ((sizeof($rec_list_1) > '0') and (sizeof($rec_list_2) == '0'))
		        { $individual_table_id_term = join($rec_list_1,',');}
                      elseif ((sizeof($rec_list_1) == '0') and (sizeof($rec_list_2) > '0'))
                        { $individual_table_id_term = join($rec_list_2,',');}
                      else
                        {
                          $individual_table_id_term = join($rec_list_1,',');
                          $individual_table_id_term.= ",";
                          $individual_table_id_term.= join($rec_list_2,',');
                        }
                      unset($rec_list_1);
                      unset($rec_list_2);
		    }#end if sizeof(field_list) > '1'

		  $field_list_array = array('individual_table_id');
		  $rec_list = distinctTableQuery('marker_id','genotype_table',$database_id,$field_list_array,$individual_table_id_term,'in','all');
		  if (!is_array($rec_list))
		    {
		      $date = date('Y-m-d H:i:s');
		      echo "Error #168: $date<br>\n";
		      echo "Error in call to distinctTableQuery from marker_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 "Your search of the Phenotype Value Table did not yield any markers.<br>\n";
		      echo "Please change your search criteria and try a new search.<br>\n";
                      echo "<form action=\"marker_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 if (sizeof(rec_list) == '0')
		  $marker_id_term = join($rec_list,',');
                  unset($marker_id_term);

		  $field_list_array = array('marker_id');
                  $num_markers = countTableQuery('marker_table',$database_id,$field_list_array,$marker_id_term,'in');
                  if (!preg_match('/^\d+$/',$num_markers))
                    {
		      $date = date('Y-m-d H:i:s');
		      echo "Error #169: $date<br>\n";
		      echo "Error in call to countTableQuery from marker_search.php<br>\n";
		      echo "$num_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 if error in call to countTableQuery

                  #if ($num_markers > $max_records_to_print)
                  #  {
                  #    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,$marker_id_term,'in','all',$order_by);
		  #    if (!is_array($marker_id_array))
		  #      {
		  #        $date = date('Y-m-d H:i:s');
		  #        echo "Error #170: $date<br>\n";
		  #        echo "Error in call to tableQuery from marker_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_term = join($marker_id_array,',');
                  #    unset($marker_id_array);

                  #    echo "Your search returned $num_markers markers.<br>\n";
                  #    tooManyMarkers($marker_id_array);
                  #    $ret_val = disconnect();
                  #    exit;
                  #  }#end if too many markers to print

                  if ($num_markers > (5 * $max_records_to_print_per_print))
                    {
                      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,$marker_id_term,'in','all',$order_by);
		      if (!is_array($marker_id_array))
		        {
		          $date = date('Y-m-d H:i:s');
		          echo "Error #171: $date<br>\n";
		          echo "Error in call to tableQuery from marker_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_term = join($marker_id_array,',');
                      unset($marker_id_array);
                      moreThanFivePages($marker_id_term);
                      unset($marker_id_term);
                    }#end if more than 5 pages of records

                  if ($num_markers > $max_records_to_print_per_page)
                    {
                      $marker_multiple_pages = 1;
                      $from  = 0;
                      $t0    = $max_records_to_print_per_page - 1;
                      $range = "$from"."-"."$to";
                      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,$marker_id_term,'in',$range,$order_by);
		      if (!is_array($marker_rec_list))
		        {
		          $date = date('Y-m-d H:i:s');
		          echo "Error #172: $date<br>\n";
		          echo "Error in call to tableQuery from marker_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')
		        {
		          echo "Your search of the Phenotype Value Table did not yield any markers.<br>\n";
		          echo "Please change your search criteria and try a new search.<br>\n";
                          echo "<form action=\"marker_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 if (sizeof(marker_rec_list) == '0')
                      $final_function_call   = 'tableQuery';
                      $final_table_name      = 'marker_table';
                      $final_field_list      = $field_list_array;
                      $final_term            = $marker_id_term;
                      $final_mode            = 'in';
                      $final_order_by        = $order_by;
                      $last_record_retrieved = $max_records_to_print_per_page;
                    }#end if multiple pages of markers
                  else #only a single page of markers
                    {
                      $marker_multiple_pages = 0;
                      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,$marker_id_term,'in','all',$order_by);
		      if (!is_array($marker_rec_list))
		        {
		          $date = date('Y-m-d H:i:s');
		          echo "Error #173: $date<br>\n";
		          echo "Error in call to tableQuery from marker_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')
		        {
		          echo "Your search of the Phenotype Value Table did not yield any markers.<br>\n";
		          echo "Please change your search criteria and try a new search.<br>\n";
                          echo "<form action=\"marker_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 if (sizeof(marker_rec_list) == '0')
                    }#end else only a single page of markers
		 }#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_mode = $mode[$i];
			       $search_term = $term[$i];
			     }
		         }

                       $field_list = array('phenotype_name');
                       $age_phenotype_id_array = distinctTableQuery('phenotype_id','phenotype_table',$database_id,$field_list,'age','equal','all');
                       if (!is_array($age_phenotype_id_array))
                         {
                           $date = date('Y-m-d H:i:s');
		           echo "Error #174: $date<br>\n";
		           echo "Error in call to distinctTableQuery from marker_search.php<br>\n";
		           echo "$age_phenotype_id_array<br><br>\n";
		           echo "Please email the above error using the Comments/Help/Support link \n";
		           echo "on the left navigation bar.<br>\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')
                         {
                           $date = date('Y-m-d H:i:s');
                           echo "There is no \"age\" phenotype in the database.  Therefore, cannot find any pedigrees with individuals that fall within the \n";
                           echo "age group range of the age group records that meet your search criteria.  Please create the \"age\" phenotype and insert values \n";
                           echo "for individuals and try your search again.  <br>This message was generated at $date.\n";
                           echo "</form>\n";
                           echo "</body></html>\n";
                           $ret_val = disconnect();
                           exit;
                         }
                       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 #175: $date<br>\n";
                           echo "Queried the phenotype table for phenotype \"age\" in database id $database_id and multiple records were returned.<br><br>\n";
                           echo "Please email the above error using the Comments/Help/Support link \n";
		           echo "on the left navigation bar.<br>\n";
		           echo "</form>\n";
		           echo "</body></html>\n";
		           $ret_val = disconnect();
		           exit;
                         }#end more than one age phenotype

                       $age_group_rec_list = tableQuery($table_name,$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 marker_search.php<br>\n";
		           echo "$age_group_rec_list<br><br>\n";
		           echo "Please email the above error using the Comments/Help/Support link \n";
		           echo "on the left navigation bar.<br>\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 yeild any pedigrees.<br>\n";
		           echo "Please try again with different search criteria.<br>\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')

                       $individual_table_id_array = array();
                       foreach ($age_group_rec_list as $age_group_rec)
                         {
                           $age_group_min_age = $age_group_rec['age_group_min_age'];
                           $query_min_age     = $age_group_min_age - 1;
                           $age_group_max_age = $age_group_rec['age_group_max_age'];
                           $query_max_age     = $age_group_max_age + 1;

                           $field_list_array = array('nationality');
                           $nat_indiv_table_id_array = distinctTableJoin('individual_table_id','pedigree_table','individual_table',$database_id,$field_list_array,$age_group_nationality,'equal','all');
                           if (!is_array($nat_indiv_table_id_array))
                             {
                               $date = date('Y-m-d H:i:s');
                               echo "Error #177: $date<br>\n";
                               echo "Error in call to distinctTableJoin from marker_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 \n";
		               echo "on the left navigation bar.<br>\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'){continue;}
                           $nat_indiv_table_id_term = join($nat_indiv_table_id_array,',');
                           unset($nat_indiv_table_id_array);
                      
                           $field_list = array('phenotype_id','phenotype_value','phenotype_value','individual_table_id');
                           $term_array = array($age_phenotype_id,$query_min_age,$query_max_age,$nat_indiv_table_id_term);
                           $mode_array = array('equal','greater_than','less_than','in');
                           $rec_list = distinctCompoundTableQuery('individual_table_id','quantitative_phenotype_value_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 #178: $date<br>\n";
                               echo "Error in call to distinctCompoundTableQuery from marker_search.php<br>\n";
                               echo "$rec_list<br><br>\n";
                               echo "Please email the above error using the Comments/Help/Support link \n";
		               echo "on the left navigation bar.<br>\n";
		               echo "</form>\n";
		               echo "</body></html>\n";
		               $ret_val = disconnect();
		               exit;
                             }#end error in call to distinctCompoundTableQuery
                           if (sizeof($rec_list) == '0') {continue;}
                           else
                             {
                               $indiv_table_id_term = join($rec_list,',');
                               $individual_table_id_array[] = $indiv_table_id_term;
                               unset($indiv_table_id_term);
                             }#end else have records
                         }#end foreach age group record

                       if (sizeof($individual_table_id_array) == '0')
                         {
                           echo "<center>\n";
		           echo "Your search of the Age Group Table did not yeild any pedigrees.<br>\n";
		           echo "Please try again with different search criteria.<br>\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')
                       $individual_table_id_term = join($individual_table_id_array,',');
                       unset($individual_table_id_array);
		     }#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_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
			         }#end if real mode
			     }#end foreach mode
		         }#end foreach field

                       $field_list = array('phenotype_name');
                       $age_phenotype_id_array = distinctTableQuery('phenotype_id','phenotype_table',$database_id,$field_list,'age','equal','all');
                       if (!is_array($age_phenotype_id_array))
                         {
                           $date = date('Y-m-d H:i:s');
		           echo "Error #179: $date<br>\n";
		           echo "Error in call to distinctTableQuery from marker_search.php<br>\n";
		           echo "$age_phenotype_id_array<br><br>\n";
		           echo "Please email the above error using the Comments/Help/Support link \n";
		           echo "on the left navigation bar.<br>\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')
                         {
                           $date = date('Y-m-d H:i:s');
                           echo "There is no \"age\" phenotype in the database.  Therefore, cannot find any pedigrees with individuals that fall within the \n";
                           echo "age group range of the age group records that meet your search criteria.  Please create the \"age\" phenotype and insert values \n";
                           echo "for individuals and try your search again.  <br>This message was generated at $date.\n";
                           echo "</form>\n";
                           echo "</body></html>\n";
                           $ret_val = disconnect();
                           exit;
                         }
                       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 #180: $date<br>\n";
                           echo "Queried the phenotype table for phenotype \"age\" in database id $database_id and multiple records were returned.<br><br>\n";
                           echo "Please email the above error using the Comments/Help/Support link \n";
		           echo "on the left navigation bar.<br>\n";
		           echo "</form>\n";
		           echo "</body></html>\n";
		           $ret_val = disconnect();
		           exit;
                         }#end more than one age phenotype

                       $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 #181: $date<br>\n";
		           echo "Error in call to compoundTableQuery from marker_search.php<br>\n";
		           echo "$age_group_rec_list<br><br>\n";
		           echo "Please email the above error using the Comments/Help/Support link \n";
		           echo "on the left navigation bar.<br>\n";
		           echo "</form>\n";
		           echo "</body></html>\n";
		           $ret_val = disconnect();
		           exit;
		         }#end error in call to compoundTableQuery
		       if (sizeof($age_group_rec_list) == '0')
		         {
		           echo "<center>\n";
		           echo "Your search of the Age Group Table did not yeild any pedigrees.<br>\n";
		           echo "Please try again with different search criteria.<br>\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')
                    
                       $individual_table_id_array = array();
                       foreach ($age_group_rec_list as $age_group_rec)
                         {
                           $age_group_min_age = $age_group_rec['age_group_min_age'];
                           $query_min_age     = $age_group_min_age - 1;
                           $age_group_max_age = $age_group_rec['age_group_max_age'];
                           $query_max_age     = $age_group_max_age + 1;

                           $field_list_array = array('nationality');
                           $nat_indiv_table_id_array = distinctTableJoin('individual_table_id','pedigree_table','individual_table',$database_id,$field_list_array,$age_group_nationality,'equal','all');
                           if (!is_array($nat_indiv_table_id_array))
                             {
                               $date = date('Y-m-d H:i:s');
                               echo "Error #182: $date<br>\n";
                               echo "Error in call to distinctTableJoin from marker_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 \n";
		               echo "on the left navigation bar.<br>\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'){continue;}
                           $nat_indiv_table_id_term = join($nat_indiv_table_id_array,',');
                           unset($nat_indiv_table_id_array);
                      
                           $field_list = array('phenotype_id','phenotype_value','phenotype_value','individual_table_id');
                           $term_array = array($age_phenotype_id,$query_min_age,$query_max_age,$nat_indiv_table_id_term);
                           $mode_array = array('equal','greater_than','less_than','in');
                           $rec_list = distinctCompoundTableQuery('individual_table_id','quantitative_phenotype_value_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 #183: $date<br>\n";
                               echo "Error in call to distinctCompoundTableQuery from marker_search.php<br>\n";
                               echo "$rec_list<br><br>\n";
                               echo "Please email the above error using the Comments/Help/Support link \n";
		               echo "on the left navigation bar.<br>\n";
		               echo "</form>\n";
		               echo "</body></html>\n";
		               $ret_val = disconnect();
		               exit;
                             }#end error in call to distinctCompoundTableQuery
                           if (sizeof($rec_list) == '0') {continue;}
                           else
                             {
                               $indiv_table_id_term = join($rec_list,',');
                               $individual_table_id_array[] = $indiv_table_id_term;
                               unset($indiv_table_id_term);
                             }#end else have records
                         }#end foreach age group record

                       if (sizeof($individual_table_id_array) == '0')
                         {
                           echo "<center>\n";
		           echo "Your search of the Age Group Table did not yeild any pedigrees.<br>\n";
		           echo "Please try again with different search criteria.<br>\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')
                       $individual_table_id_term = join($individual_table_id_array,',');
                       unset($individual_table_id_array);
		     }#end else sizeof(field_list) > 1
		

		  $field_list_array = array('individual_table_id');
		  $rec_list = distinctTableQuery('marker_id','genotype_table',$database_id,$field_list_array,$individual_table_id_term,'in','all');
		  if (!is_array($rec_list))
		    {
		      $date = date('Y-m-d H:i:s');
		      echo "Error #184: $date<br>\n";
		      echo "Error in call to distinctTableQuery from marker_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 distinctTableQuery
	          if (sizeof($rec_list) == '0')
		    {
		      echo "Your search of the Age Group Table did not yield any markers.<br>\n";
		      echo "Please change your search criteria and try a new search.<br>\n";
                      echo "<form action=\"marker_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 if no records
		  $marker_id_term = join($rec_list,',');
                  unset($rec_list);

		  $field_list_array = array('marker_id');
                  $num_markers = countTableQuery('marker_table',$database_id,$field_list_array,$marker_id_term,'in');
                  if (!preg_match('/^\d+$/',$num_markers))
                    {
		      $date = date('Y-m-d H:i:s');
		      echo "Error #185: $date<br>\n";
		      echo "Error in call to tableQuery from marker_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 error in call to countTableQuery

                  #if ($num_markers > $max_records_to_print)
                  #  {
                  #    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,$marker_id_term,'in','all',$order_by);
		  #    if (!is_array($marker_id_array))
		  #      {
		  #        $date = date('Y-m-d H:i:s');
		  #        echo "Error #186: $date<br>\n";
		  #        echo "Error in call to distinctTableQuery from marker_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_term = join($marker_id_array,',');
                  #    unset($marker_id_array);

                  #    tooManyMarkers($marker_id_term);
                  #    $ret_val = disconnect();
                  #    exit;
                  #  }#end if too many markers to get through web

                  if ($num_markers > (5 * $max_records_to_print_per_page))
                    {
                      $marker_id_array = distinctTableQuery('marker_id','marker_table',$database_id,$field_list_array,$marker_id_term,'in','all',$order_by);
		      if (!is_array($marker_id_array))
		        {
		          $date = date('Y-m-d H:i:s');
		          echo "Error #187: $date<br>\n";
		          echo "Error in call to distinctTableQuery from marker_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_term = join($marker_id_array,',');
                      unset($marker_id_array);

                      moreThanFivePages($marker_id_term);
                      unset($marker_id_term);
                    }#end if more than 5 pages of records 

                  if ($num_markers > $max_records_to_print_per_page)
                    {
                      $marker_multiple_pages = 1;
                      $from  = 0;
                      $to    = $max_records_to_print_per_page - 1;
                      $range = "$from"."-"."$to";
                      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,$marker_id_term,'in',$range,$order_by);
		      if (!is_array($marker_rec_list))
		        {
		          $date = date('Y-m-d H:i:s');
		          echo "Error #188: $date<br>\n";
		          echo "Error in call to tableQuery from marker_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')
		        {
		          echo "Your search of the Age Group Table did not yield any markers.<br>\n";
		          echo "Please change your search criteria and try a new search.<br>\n";
                          echo "<form action=\"marker_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 if (sizeof(marker_rec_list) == '0')
                      $final_function_call    = 'tableQuery';
                      $final_table_name       = 'marker_table';
                      $final_field_list       = $field_list_array;
                      $final_term             = $marker_id_term;
                      $final_mode             = 'in';
                      $final_order_by         = $order_by;
                      $last_record_retrieved = $max_records_to_print_per_page;
                    }#end if multiple pages of markers
                  else #only a single page of markers
                    {
                      $marker_multiple_pages = 0;
                      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,$marker_id_term,'in','all',$order_by);
		      if (!is_array($marker_rec_list))
		        {
		          $date = date('Y-m-d H:i:s');
		          echo "Error #189: $date<br>\n";
		          echo "Error in call to tableQuery from marker_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')
		        {
		          echo "Your search of the Age Group Table did not yield any markers.<br>\n";
		          echo "Please change your search criteria and try a new search.<br>\n";
                          echo "<form action=\"marker_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 if (sizeof(marker_rec_list) == '0')
                    }#end else only a single page of markers
		 }#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 #190: $date<br>\n";
                                echo "Error in call to tableQuery from marker_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 markers.<br>\n";
		                echo "Please try a new search with different search criteria.<br><br>\n";
				echo "<form action=\"marker_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 #191: $date<br>\n";
                                echo "Error in call to distinctTableQuery from marker_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=\"marker_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 #192: $date<br>\n";
                                echo "Error from marker_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 ($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 #193: $date<br>\n";
				    echo "Error in call to distinctTableJoin from marker_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 distinctTableQuery
			        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 #194: $date<br>\n";
				        echo "Error in call to distinctCompoundTableQuery from marker_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 markers.<br>\n";
		                echo "Please try a new search with different search criteria.<br><br>\n";
			        echo "<form action=\"marker_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')
                          {
                            $indiv_table_id_array = array();
                            $qual_indiv_table_id_array = distinctTableJoin('individual_table_id','phenotype_table','qualitative_phenotype_value_table',$database_id,$field_list,$search_term,$search_mode,'all');
                            if (!is_array($qual_indiv_table_id_array))
                              {
				$date = date('Y-m-d H:i:s');
                                echo "Error #195: $date<br>\n";
                                echo "Error in call to distinctTableJoin from marker_search.php<br>\n";
                                echo "$qual_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($qual_indiv_table_id_array) > '0')
                              {
                                $qual_indiv_table_id_term = join($qual_indiv_table_id_array,',');
                                $indiv_table_id_array[] = $qual_indiv_table_id_term;
                                unset($qual_indiv_table_id_term);
                              }
                            unset($qual_indiv_table_id_array);

                            $quant_indiv_table_id_array = distinctTableJoin('individual_table_id','phenotype_table','quantitative_phenotype_value_table',$database_id,$field_list,$search_term,$search_mode,'all');
                            if (!is_array($quant_indiv_table_id_array))
                              {
				$date = date('Y-m-d H:i:s');
                                echo "Error #196: $date<br>\n";
                                echo "Error in call to distinctTableJoin from marker_search.php<br>\n";
                                echo "$quant_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($quant_indiv_table_id_array) > '0')
                              {
                                $quant_indiv_table_id_term = join($quant_indiv_table_id_array,',');
                                $indiv_table_id_array[] = $quant_indiv_table_id_term;
                                unset($quant_indiv_table_id_term);
                              }
                            unset($quant_indiv_table_id_array);

                            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 markers.<br>\n";
		                echo "Please try a new search with different search criteria.<br><br>\n";
			        echo "<form action=\"marker_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 
                            $indiv_table_id_term = join($indiv_table_id_array,',');
			    unset($indiv_table_id_array);
                          }#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 #197: $date<br>\n";
				    echo "Error in call to tableQuery from marker_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 markers.<br>\n";
				    echo "Please try a new search with different search criteria.<br><br>\n";
				    echo "<form action=\"marker_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 #198: $date<br>\n";
				    echo "Error in call to distinctTableQuery from marker_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=\"marker_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 #199: $date<br>\n";
				    echo "Error in call to marker_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('phenotype_id');
                                    $pheno_rec_list = tableQuery('phenotype_table',$database_id,$field_list_array,$phenotype_id,'equal','all');
                                    if (!is_array($pheno_rec_list))
                                      {
                                        $date = date('Y-m-d H:i:s');
                                        echo "Error #200: $date<br>\n";
                                        echo "Error in call to tableQuery from marker_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 error in call to tableQuery
                                    if (sizeof($pheno_rec_list) == 1)
                                      {
                                        $pheno_rec = $pheno_rec_list[0];
                                        $type_of_phenotype = $pheno_rec['type_of_phenotype'];
                                      }
                                    else #error in data integrity
                                      {
                                        $date = date('Y-m-d H:i:s');
					echo "Error #201: $date<br>\n";
					echo "Error in call to marker_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 phenotype_id $phenotype_id, but when query the phenotype_table with that id ".sizeof($pheno_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
                                    unset($pheno_rec);
                                    unset($pheno_rec_list);

				    $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 #202: $date<br>\n";
					echo "Error in call to tableQuery from marker_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 #203: $date<br>\n";
					echo "Error in call to marker_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 #204: $date<br>\n";
					echo "Error in call to distinctTableQuery from marker_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 #205: $date<br>\n";
					    echo "Error in call to distinctCompoundTableQuery from marker_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 #206: $date<br>\n";
						echo "Error in call to distinctCompoundTableQuery from marker_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);
                                            if ($type_of_phenotype == 'qualitative')
                                              {
                                                $indiv_ids = distinctCompoundTableQuery('individual_table_id','qualitative_phenotype_value_table',$databse_id,$query_field_list,$query_term_array,$query_mode_array,'and','all');
                                              }
                                            if ($type_of_phenotype == 'quantitative')
                                              {
					        $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 #207: $date<br>\n";
						echo "Error in call to distinctCompoundTableQuery from marker_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 markers.<br>\n";
				    echo "Please try a new search with different search criteria.<br><br>\n";
				    echo "<form action=\"marker_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 #208: $date<br>\n";
				    echo "Error in call to tableQuery from marker_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 markers.<br>\n";
				    echo "Please try a new search with different search criteria.<br><br>\n";
				    echo "<form action=\"marker_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 #209: $date<br>\n";
				    echo "Error in call to distinctTableQuery from marker_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=\"marker_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 #210: $date<br>\n";
				    echo "Error in call to marker_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('phenotype_id');
                                    $pheno_rec_list = tableQuery('phenotype_table',$database_id,$field_list_array,$phenotype_id,'equal','all');
                                    if (!is_array($pheno_rec_list))
                                      {
                                        $date = date('Y-m-d H:i:s');
                                        echo "Error #211: $date<br>\n";
                                        echo "Error in call to tableQuery from marker_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 error in call to tableQuery
                                    if (sizeof($pheno_rec_list) == 1)
                                      {
                                        $pheno_rec = $pheno_rec_list[0];
                                        $type_of_phenotype = $pheno_rec['type_of_phenotype'];
                                      }
                                    else #error in data integrity
                                      {
                                        $date = date('Y-m-d H:i:s');
					echo "Error #212: $date<br>\n";
					echo "Error in call to marker_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 phenotype_id $phenotype_id, but when query the phenotype_table with that id ".sizeof($pheno_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
                                    unset($pheno_rec);
                                    unset($pheno_rec_list);

				    $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 #213: $date<br>\n";
					echo "Error in call to tableQuery from marker_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 #214: $date<br>\n";
					echo "Error in call to marker_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 #215: $date<br>\n";
					echo "Error in call to distinctTableJoin from marker_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 #216: $date<br>\n";
					    echo "Error in call to distinctCompoundTableQuery from marker_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');
                                        if ($type_of_phenotype == 'qualitative')
                                          {
                                            $indiv_ids = distinctCompoundTableQuery('individual_table_id','qualitative_phenotype_value_table',$databse_id,$query_field_list,$query_term_array,$query_mode_array,'and','all');
                                          }
                                        if ($type_of_phenotype == 'quantitative')
                                          {
					    $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 #217: $date<br>\n";
					    echo "Error in call to distinctCompoundTableQuery from marker_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 markers.<br>\n";
				    echo "Please try a new search with different search criteria.<br><br>\n";
				    echo "<form action=\"marker_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');
                        $marker_id_array = distinctTableQuery('marker_id','genotype_table',$database_id,$field_list_array,$indiv_table_id_term,'in','all');
                        if (!is_array($marker_id_array))
                          {
                            $date = date('Y-m-d H:i:s');
                            echo "Error #218: $date<br>\n";
                            echo "Error in call to distinctTableQuery from marker_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 Age Group-Phenotype Percentile Link Table did not yield any markers.<br>\n";
		            echo "Please try a new search with different search criteria.<br><br>\n";
			    echo "<form action=\"marker_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(marker_id_array) == 0
                        $marker_id_term = join($marker_id_array,',');
                        unset($marker_id_array);
                      }#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 #219: $date<br>\n";
                                    echo "Error in call to distinctCompoundTableQuery from marker_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 markers.<br>\n";
		                        echo "Please try a new search with different search criteria.<br>\n";
					echo "<form action=\"marker_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 #220: $date<br>\n";
                                    echo "Error in call to distinctTableQuery from marker_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 markers.<br>\n";
		                        echo "Please try a new search with different search criteria.<br>\n";
					echo "<form action=\"marker_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 #221: $date<br>\n";
                                echo "Error in call to distinctTableQuery from marker_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 markers.<br>\n";
		                    echo "Please try a new search with different search criteria.<br>\n";
				    echo "<form action=\"marker_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 #222: $date<br>\n";
                            echo "Error in call to compoundTableQuery from marker_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 markers.<br>\n";
		            echo "Please try a new search with different search criteria.<br><br>\n";
			    echo "<form action=\"marker_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 #223: $date<br>\n";
                            echo "Error in call to distinctTableQuery from marker_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=\"marker_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 #224: $date<br>\n";
                            echo "Error from marker_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($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('phenotype_id');
                            $pheno_rec_list = tableQuery('phenotype_table',$database_id,$field_list_array,$phenotype_id,'equal','all');
                            if (!is_array($pheno_rec_list))
                              {
                                $date = date('Y-m-d H:i:s');
                                echo "Error #225: $date<br>\n";
                                echo "Error in call to tableQuery from marker_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 error in call to tableQuery
                            if (sizeof($pheno_rec_list) == 1)
                              {
                                $pheno_rec = $pheno_rec_list[0];
                                $type_of_phenotype = $pheno_rec['type_of_phenotype'];
                              }
                            else #error in data integrity
                              {
                                $date = date('Y-m-d H:i:s');
				echo "Error #226: $date<br>\n";
				echo "Error in call to marker_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 phenotype_id $phenotype_id, but when query the phenotype_table with that id ".sizeof($pheno_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
                            unset($pheno_rec);
                            unset($pheno_rec_list);

			    $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 #227: $date<br>\n";
				echo "Error in call to tableQuery from marker_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 #228: $date<br>\n";
				echo "Error in call to marker_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 #229: $date<br>\n";
				echo "Error in call to distinctTableQuery from marker_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 #230: $date<br>\n";
				    echo "Error in call to distinctCompoundTableQuery from marker_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 #231: $date<br>\n";
						echo "Error in call to distinctCompoundTableQuery from marker_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 #232: $date<br>\n";
						echo "Error in call to distinctCompoundTableQuery from marker_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];
                                                  }
                                              }
                                            if ($type_of_phenotype == 'qualitative')
                                              {
                                                $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 ($type_of_phenotype == 'quantitative')
                                              {
					        $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 #233: $date<br>\n";
						echo "Error in call to distinctCompoundTableQuery from marker_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 #234: $date<br>\n";
						echo "Error in call to distinctCompoundTableQuery from marker_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 #235: $date<br>\n";
						echo "Error in call to distinctCompoundTableQuery from marker_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];
                                                  }
                                              }
                                            if ($type_of_phenotype == 'qualitative')
                                              {
                                                $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 ($type_of_phenotype == 'quantitative')
                                              {
					        $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 #236: $date<br>\n";
						echo "Error in call to distinctCompoundTableQuery from marker_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 #237: $date<br>\n";
						echo "Error in call to distinctCompoundTableQuery from marker_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];
                                              }
                                            if ($type_of_phenotype == 'qualitative')
                                              {
                                                $indiv_ids = distinctCompoundTableQuery('individual_table_id','qualitative_phenotype_value_table',$databse_id,$query_field_list,$query_term_array,$query_mode_array,'and','all');
                                              }
                                            if ($type_of_phenotype == 'quantitative')
                                              {
					        $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 #238: $date<br>\n";
						echo "Error in call to distinctCompoundTableQuery from marker_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 #239: $date<br>\n";
					    echo "Error in call to distinctCompoundTableQuery from marker_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');
                                        if ($type_of_phenotype == 'qualitative')
                                          {
                                            $indiv_ids = distinctCompoundTableQuery('individual_table_id','qualitative_phenotype_value_table',$databse_id,$query_field_list,$query_term_array,$query_mode_array,'and','all');
                                          }
                                        if ($type_of_phenotype == 'quantitative')
                                          {
                                            $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 #240: $date<br>\n";
					    echo "Error in call to distinctCompoundTableQuery from marker_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 markers.<br>\n";
			    echo "Please try a new search with different search criteria.<br><br>\n";
			    echo "<form action=\"marker_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');
                        $marker_id_array = distinctTableQuery('marker_id','genotype_table',$database_id,$field_list_array,$indiv_table_id_term,'in','all');
                        if (!is_array($marker_id_array))
                          {
                            $date = date('Y-m-d H:i:s');
                            echo "Error #241: $date<br>\n";
			    echo "Error in call to distinctTableQuery from marker_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 Age Group-Phenotype Percentile Link Table did not yield any markers.<br>\n";
			    echo "Please try a new search with different search criteria.<br><br>\n";
			    echo "<form action=\"marker_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(marker_id_array) == 0
                        $marker_id_term = join($marker_id_array,',');
                        unset($marker_id_array);
                      }#end else sizeof(field_list) > '1'

                    $field_list_array = array('marker_id');
                    $num_markers =  countTableQuery('marker_table',$database_id,$field_list_array,$marker_id_term,'in');
                    if (!preg_match('/^\d+$/',$num_markers))
                      {
                        $date = date('Y-m-d H:i:s');
                        echo "Error #242: $date<br>\n";
                        echo "Error in callto countTableQuery from marker_search.php<br>\n";
                        echo "$num_markers<br><br>\n";
                        echo "Please email the above error message using 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 ($num_markers > $max_records_to_print)
                    #  {
                    #    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,$marker_id_term,'in','all',$order_by);
		    #    if (!is_array($marker_id_array))
		    #      {
		    #        $date = date('Y-m-d H:i:s');
		    #        echo "Error #243: $date<br>\n";
		    #        echo "Error in call to distinctTableQuery from marker_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_term = join($marker_id_array,',');
                    #    unset($marker_id_array);

                    #    tooManyMarkers($marker_id_term);
                    #    $ret_val = disconnect();
                    #    exit;
                    #  }#end if too many markers to get through web

                    if ($num_markers > (5 * $max_records_to_print_per_page))
                      {
                        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,$marker_id_term,'in','all',$order_by);
		        if (!is_array($marker_id_array))
		          {
		            $date = date('Y-m-d H:i:s');
		            echo "Error #244: $date<br>\n";
		            echo "Error in call to distinctTableQuery from marker_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_term = join($marker_id_array,',');
                        unset($marker_id_array);

                        moreThanFivePages($marker_id_term);
                        unset($marker_id_term);
                      }#end if more than 5 pages of records 

                    if ($num_markers > $max_records_to_print_per_page)
                      {
                        $marker_multiple_pages = 1;
                        $from  = 0;
                        $to    = $max_records_to_print_per_page - 1;
                        $range = "$from"."-"."$to";
                        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,$marker_id_term,'in',$range,$order_by);
		        if (!is_array($marker_rec_list))
		          {
		            $date = date('Y-m-d H:i:s');
		            echo "Error #245: $date<br>\n";
		            echo "Error in call to tableQuery from marker_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')
		          {
		            echo "Your search of the Age Group-Phenotype Percentile Link Table did not yield any markers.<br>\n";
		            echo "Please change your search criteria and try a new search.<br>\n";
                            echo "<form action=\"marker_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 if (sizeof(marker_rec_list) == '0')
                        $final_function_call    = 'tableQuery';
                        $final_table_name       = 'marker_table';
                        $final_field_list       = $field_list_array;
                        $final_term             = $marker_id_term;
                        $final_mode             = 'in';
                        $final_order_by         = $order_by;
                        $last_record_retrieved = $max_records_to_print_per_page;
                      }#end if multiple pages of markers
                    else #only a single page of markers
                      {
                        $marker_multiple_pages = 0;
                        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,$marker_id_term,'in','all',$order_by);
		        if (!is_array($marker_rec_list))
		          {
		            $date = date('Y-m-d H:i:s');
		            echo "Error #246: $date<br>\n";
		            echo "Error in call to tableQuery from marker_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')
		          {
		            echo "Your search of the Age Group-Phenotype Percentile Link Table did not yield any markers.<br>\n";
		            echo "Please change your search criteria and try a new search.<br>\n";
                            echo "<form action=\"marker_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 if (sizeof(marker_rec_list) == '0')
                      }#end else only a single page of markers
                 }#end if table_name == age_group_phenotype_percentile_link_table

	       else #not a known searchable table in the database
		 {
		   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 "<center><input type=\"submit\" name=\"submit\" value=\"Start a New Seach\"></center>\n";
		   echo "</form>\n";
		   echo "</body></html>\n";
		   $ret_val = disconnect();
		   exit;
		 }#end else not a searchable table

               #echo "Your search returned <b>$num_markers</b> Markers.<br>\n";
               #echo "Please select the Affection Status and Markers you want to investigate:<br><br>\n";

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

               echo "<table align=\"center\">\n";
               if ($marker_multiple_pages)
                 {
                   echo "<tr>\n";
                   echo "<form action=\"download.php\" name=\"download_form1\" method=\"POST\" target=\"main\" onSubmit=\"return(skipValidate(form))\">\n";
                   echo "<input type=\"hidden\" name=\"type_of_download\" value=\"marker_record\">\n";
                   echo "<input type=\"hidden\" name=\"marker_id\" value=\"\">\n";
                   echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Marker Information\" onClick=\"copyData('download','download_form1')\"></td>\n";
                   echo "<td>&nbsp;</td>\n";
                   echo "</form>\n\n";

                   echo "<form action=\"calculate_hardy_weinberg.php\" name=\"hwe_form1\" method=\"POST\" target=\"main\" onSubmit=\"return(skipValidate(form))\">\n";
                   echo "<input type=\"hidden\" name=\"how_to_select\" value=\"marker_search\">\n";
                   echo "<input type=\"hidden\" name=\"marker_id\" value=\"\">\n";
                   echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Calculate HWE for Marker(s)\" onClick=\"copyData('hwe','hwe_form1')\"></td>\n";
                   echo "</tr>\n";
                   echo "<tr><td>&nbsp;</td></tr>\n";
                   echo "</form>\n\n";

                   echo "<tr>\n";
                   echo "<form action=\"marker_search.php\" name=\"skip_form1\" method=\"POST\" target=\"main\" onSubmit=\"return(skipValidate(form))\">\n";
                   echo "<input type=\"hidden\" name=\"status\" value=\"\">\n";
                   echo "<input type=\"hidden\" name=\"marker_flag\" value=\"1\">\n";
                   echo "<input type=\"hidden\" name=\"marker_multiple_pages\" value=\"0\">\n";
                   echo "<input type=\"hidden\" name=\"marker_id\" value=\"\">\n";
                   echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes without Phenotypes\" onClick=\"copyData('skip','skip_form1')\"></td>\n";
                   echo "<td>&nbsp;</td>\n";
                   echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Select Phenotypes to Investigate\" onClick=\"copyData('skip','skip_form1')\"></td>\n";
                   echo "</tr>\n";
                   echo "<tr><td>&nbsp;</td></tr>\n";
                   echo "</form>\n\n";

                   $records_left = $num_markers - $max_records_to_print_per_page;
                   echo "<tr>\n";
                   echo "<form action=\"marker_search.php\" name=\"form\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\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 #rest of markers will fit on one page
                     {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Next $records_left Markers\"></td>\n";}
                   echo "<td>&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><br>\n";
                 }#end if multiple pages of markers to select
               else #only a single page of markers
                 {
                   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=\"marker_record\">\n";
                   echo "<input type=\"hidden\" name=\"marker_id\" value=\"\">\n";
                   echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Marker Information\" onClick=\"copyData('download','download_form1')\"></td>\n";
                   echo "<td>&nbsp;</td>\n";
                   echo "</form>\n\n";

                   echo "<form action=\"calculate_hardy_weinberg.php\" name=\"hwe_form1\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";
                   echo "<input type=\"hidden\" name=\"how_to_select\" value=\"marker_search\">\n";
                   echo "<input type=\"hidden\" name=\"marker_id\" value=\"\">\n";
                   echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Calculate HWE for Marker(s)\" onClick=\"copyData('hwe','hwe_form1')\"></td>\n";
                   echo "</tr>\n";
                   echo "<tr><td>&nbsp;</td></tr>\n";
                   echo "</form>\n\n";

                   echo "<tr>\n";
                   echo "<form action=\"marker_search.php\" name=\"form\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";
                   echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes without Phenotypes\"></td>\n";
                   echo "<td>&nbsp;</td>\n";
	           echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Select Phenotypes to Investigate\"></td>\n";
                   echo "</tr>\n";
                   echo "<tr><td>&nbsp;</td></tr>\n";
                   echo "<tr>\n";
                   echo "<td>&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><br>\n";
                 }#end else only a single page of markers

               #Print out the form elements: Status Select List and List of Checkboxes for Markers
               echo "<b>Affection Status:</b>&nbsp;";
               $jscript_1 = printStatusSelectList($database_id);
               if ($jscript_1 == '0')
                 {
                   $date = date('Y-m-d H:i:s');
                   echo "Error #247: $date<br>\n";
		   echo "Error in call to printStatusSelectList from marker_search.php<br>\n";
		   echo "See above error from printStatusSelectList 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_1 == '0')
               if ($jscript_1 == 'no_defined_statuses')
                 {
                   $date = date('Y-m-d H:i:s');
                   echo "This message was generated at $date.<br><br>\n";
                   echo "Continue without selecting a status.<br>\n";
                   echo "<input type=\"hidden\" name=\"status\" value=\"no_defined_statuses\">\n";
                 }#end if no statuses to select
               echo "<br><br>\n";

		$jscript_2 = printMarkerCheckList($marker_rec_list);
		if ($jscript == '0')
		  {
		    $date = date('Y-m-d H:i:s');
		    echo "Error #248: $date<br>\n";
		    echo "Error in call to printMarkerCheckList from marker_search.php<br>\n";
		    echo "See above error 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_2 == '0')
                if ($marker_multiple_pages)
                  {
                    if ($jscript_1 == 'no_defined_statuses')
                      {
                        $main_form_jscript_2 = preg_replace('/^\{.+else\{return true;\}\n\}/s','{}',$jscript_2);
                        $skip_form_jscript_2 = preg_replace('/function CheckAllMarkers(form).+\}$/s','',$jscript_2);
                        $jscript = $main_form_jscript_2;
                        $jscript.= "\n";
                        $jscript.= "function skipValidate(form)\n";
                        $jscript.= "$skip_form_jscript_2\n";
                      }
                    else 
                      {
                        $main_form_jscript_2 = preg_replace('/^\{.+else\{return true;\}\n\}/s','',$jscript_2);
                        $skip_form_jscript_1 = preg_replace('/ else \{return true;\}\n\}/','',$jscript_1);
                        $skip_form_jscript_2 = preg_replace('/^\{\n/','',$jscript_2);
                        $skip_form_jscript_2 = preg_replace('/function CheckAllMarkers.+\}$/s','',$skip_form_jscript_2);
                        $jscript = "$jscript_1$main_form_jscript_2\n";
                        $jscript.= "\n";
                        $jscript.= "function skipValidate(form)\n";
                        $jscript.= "$skip_form_jscript_1$skip_form_jscript_2\n";
                      }
                  }#end if multiple pages if markers
                else #only a single page of markers
                  {
                    if ($jscript_1 == 'no_defined_statuses') {$jscript = $jscript_2;}
                    else
                      {
		        $jscript_1 = preg_replace('/ else \{return true;\}\n\}/','',$jscript_1);
		        $jscript_2 = preg_replace('/^\{\n/','',$jscript_2);
		        $jscript = "$jscript_1\n$jscript_2";
                      }
                  }#end else only a single page of markers
                unset($marker_rec_list);

               echo "<input type=\"hidden\" name=\"marker_flag\" value=\"1\">\n";
               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\" name=\"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 "<br><br>\n";
	           echo "<table align=\"center\">\n";
                   echo "<tr>\n";
                   echo "<td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Reset Selections\"></td>\n";
                   echo "<td>&nbsp;</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 #the rest of the markers will fit on one page
                     {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 "<tr><td>&nbsp;</td></tr>\n";
                   echo "<tr>\n";
                   echo "<form action=\"marker_search.php\" name=\"skip_form2\" method=\"POST\" target=\"main\" onSubmit=\"return(skipValidate(form))\">\n";
                   echo "<input type=\"hidden\" name=\"status\" value=\"\">\n";
                   echo "<input type=\"hidden\" name=\"marker_flag\" value=\"1\">\n";
                   echo "<input type=\"hidden\" name=\"marker_multiple_pages\" value=\"0\">\n";
                   echo "<input type=\"hidden\" name=\"marker_id\" value=\"\">\n";
                   echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes without Phenotypes\" onClick=\"copyData('skip','skip_form2')\"></td>\n";
                   echo "<td>&nbsp;</td>\n";
                   echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Select Phenotypes to Investigate\" onClick=\"copyData('skip','skip_form2')\"></td>\n";
                   echo "</tr>\n";
                   echo "</form>\n\n";

                   echo "<tr><td>&nbsp;</td></tr>\n";
                   echo "<tr>\n";
                   echo "<form action=\"download.php\" name=\"download_form2\" method=\"POST\" target=\"main\" onSubmit=\"return(skipValidate(form))\">\n";
                   echo "<input type=\"hidden\" name=\"type_of_download\" value=\"marker_record\">\n";
                   echo "<input type=\"hidden\" name=\"marker_id\" value=\"\">\n";
                   echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Marker Information\" onClick=\"copyData('download','download_form2')\"></td>\n";
                   echo "<td>&nbsp;</td>\n";
                   echo "</form>\n\n";

                   echo "<form action=\"calculate_hardy_weinberg.php\" name=\"hwe_form2\" method=\"POST\" target=\"main\" onSubmit=\"return(skipValidate(form))\">\n";
                   echo "<input type=\"hidden\" name=\"how_to_select\" value=\"marker_search\">\n";
                   echo "<input type=\"hidden\" name=\"marker_id\" value=\"\">\n";
                   echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Calculate HWE for Marker(s)\" onClick=\"copyData('hwe','hwe_form2')\"></td>\n";
                   echo "</tr>\n";
                   echo "</form>\n\n";
                 }#end if have multiple pages of markers to display
               else #only a single page of makers
                 {
                   echo "<br><br>\n";
	           echo "<table align=\"center\">\n";
                   echo "<tr><td>&nbsp;</td><td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Reset Selections\"></td></tr>\n";
                   echo "<tr><td>&nbsp;</td></tr>\n";
                   echo "<tr>\n";
	           echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes without Phenotypes\"></td>\n";
                   echo "<td>&nbsp;</td>\n";
	           echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Select Phenotypes to Investigate\"></td>\n";
                   echo "</tr>\n";
                   echo "</form>\n\n";

                   echo "<tr><td>&nbsp;</td></tr>\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=\"marker_record\">\n";
                   echo "<input type=\"hidden\" name=\"marker_id\" value=\"\">\n";
                   echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Marker Information\" onClick=\"copyData('download','download_form2')\"></td>\n";
                   echo "<td>&nbsp;</td>\n";
                   echo "</form>\n\n";

                   echo "<form action=\"calculate_hardy_weinberg.php\" name=\"hwe_form2\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";
                   echo "<input type=\"hidden\" name=\"how_to_select\" value=\"marker_search\">\n";
                   echo "<input type=\"hidden\" name=\"marker_id\" value=\"\">\n";
                   echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Calculate HWE for Marker(s)\" onClick=\"copyData('hwe','hwe_form2')\"></td>\n";
                   echo "</tr>\n";
                   echo "</form>\n\n";
                 }#end else only a single page of markers
               echo "</table>\n";

               echo "<br><br>\n";
               $ret_val = printLogOutButton('marker_search.php');
               echo "\n\n";
		    
	       echo "<script>\n";
               echo "function Validate(form)\n";
	       echo "$jscript\n";
               echo "\n";
               echo "function copyData(type,formname)\n";
               echo "{\n";
               echo "  var marker_string = new Array();\n";
               echo "  var length = 0;\n";
               echo "  if (document.form.elements['marker_id[]'].length > 1){\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 "  else{\n";
               echo "    if (document.form.elements['marker_id[]'].checked){\n";
               echo "      length = marker_string.length;\n";
               echo "      marker_string[length] = document.form.elements['marker_id[]'].value;}}\n";
               echo "  if (formname == 'hwe_form1'){\n";
               echo "    document.hwe_form1.marker_id.value = marker_string;}\n";
               echo "  if (formname == 'hwe_form2'){\n";
               echo "    document.hwe_form2.marker_id.value = marker_string;}\n";
               echo "  if (formname == 'skip_form1'){\n";
               echo "    document.skip_form1.status.value = document.form.status.value;\n";
               echo "    document.skip_form1.marker_id.value = marker_string;}\n";
               echo "  if (formname == 'skip_form2'){\n";
               echo "    document.skip_form2.status.value = document.form.status.value;\n";
               echo "    document.skip_form2.marker_id.value = marker_string;}\n";
               echo "  if (formname == 'download_form1'){\n";
               echo "    document.download_form1.marker_id.value = marker_string;}\n";
               echo "  if (formname == 'download_form2'){\n";
               echo "    document.download_form2.marker_id.value = marker_string;}\n";
               echo "}\n";
	       echo "</script>\n";
               unset($marker_multiple_pages);
               unset($marker_flag);
	  }#end if table_name,field_list,term,mode
      }#end if (marker_flag != '1')#end if haven't seen marker list

    if (($marker_flag == '1') and 
        ($marker_multiple_pages == '1')
       )#if have seen marker list, but still more markers to see
      {
        echo "Select the Markers you want data for:<br><br>\n";

        if ($function_to_call == 'tableQuery')
          {
            $num_markers = countTableQuery($table_name,$database_id,$field_list,$term,$mode);
	    if (!preg_match('/^\d+$/',$num_markers))
	      {
		$date = date('Y-m-d H:i:s');
		echo "Error #249: $date<br>\n";
		echo "Error in call to countTableQuery from marker_search.php<br>\n";
		echo "$num_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_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 #250: $date<br>\n";
		    echo "Error in call to tableQuery from marker_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 error in call to tablelQuery
		if (sizeof($marker_rec_list) == 0)
		  {
		    $date = date('Y-m-d H:i:s');
		    echo "Error #251: $date<br>\n";
		    echo "Error in call to marker_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 multiple pages
	    else #num records fit on one page
	      {
                $marker_multiple_pages = 0;
		$from = $last_record_retrieved;
		$to   = $num_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 #252: $date<br>\n";
		    echo "Error in call to tableQuery from marker_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 error in call to tableQuery
		if (sizeof($marker_rec_list) == 0)
		  {
		    $date = date('Y-m-d H:i:s');
		    echo "Error #253: $date<br>\n";
		    echo "Error in call to marker_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 == 'compoundTableQuery')
          {
	    $num_markers = countCompoundTableQuery($table_name,$database_id,$field_list,$term,$mode,$join);
	    if (!preg_match('/^\d+$/',$num_markers))
	      {
		$date = date('Y-m-d H:i:s');
		echo "Error #254: $date<br>\n";
		echo "Error in call to countCompoundTableQuery from marker_search.php<br>\n";
		echo "$num_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 countCompoundTableQuery
            $records_yet_to_be_retrieved = $num_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 = compoundTableQuery($table_name,$database_id,$field_list,$term,$mode,$join,$range,$order_by);
                if (!is_array($marker_rec_list))
		  {
		    $date = date('Y-m-d H:i:s');
		    echo "Error #255: $date<br>\n";
		    echo "Error in call to compoundTableQuery from marker_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 error in call to compoundTableQuery
                if (sizeof($marker_rec_list) == 0)
		  {
		    $date = date('Y-m-d H:i:s');
                    echo "Error #256: $date<br>\n";
		    echo "Error in call to marker_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 records to print on single page
	    else #records fit on one page
	      {
                $marker_multiple_pages = 0;
                $from = $last_record_retrieved;
                $to   = $num_markers - 1;
                $range = "$from"."-"."$to";
		$marker_rec_list = compoundTableQuery($table_name,$database_id,$field_list,$term,$mode,$join,$range,$order_by);
                if (!is_array($marker_rec_list))
		  {
		    $date = date('Y-m-d H:i:s');
		    echo "Error #257: $date<br>\n";
		    echo "Error in call to compoundTableQuery from marker_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 error in call to compoundTableQuery
                if (sizeof($marker_rec_list) == 0)
		  {
		    $date = date('Y-m-d H:i:s');
                    echo "Error #258: $date<br>\n";
		    echo "Error in call to marker_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 records fit on one page
	  }#end if compoundTableQuery

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

        echo "<table align=\"center\">\n";
	if ($records_yet_to_be_retrieved > $max_records_to_print_per_page)
	  {
            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=\"marker_record\">\n";
            echo "<input type=\"hidden\" name=\"marker_id\" value=\"\">\n";
            echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Marker Information\" onClick=\"copyData('download_form1')\"></td>\n";
            echo "<td>&nbsp;</td>\n";
            echo "</form>\n\n";

            echo "<form action=\"calculate_hardy_weinberg.php\" name=\"hwe_form1\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";
            echo "<input type=\"hidden\" name=\"how_to_select\" value=\"marker_search\">\n";
            echo "<input type=\"hidden\" name=\"marker_id\" value=\"\">\n";
            echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Calculate HWE for Marker(s)\" onClick=\"copyData('hwe_form1')\"></td>\n";
            echo "</tr>\n";
            echo "<tr><td>&nbsp;</td></tr>\n";
            echo "</form>\n\n";

            echo "<tr>\n";
            echo "<form action=\"marker_search.php\" name=\"skip_form1\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";
            echo "<input type=\"hidden\" name=\"status\" value=\"\">\n";
            echo "<input type=\"hidden\" name=\"marker_flag\" value=\"1\">\n";
            echo "<input type=\"hidden\" name=\"marker_multiple_pages\" value=\"0\">\n";
            echo "<input type=\"hidden\" name=\"marker_id\" value=\"\">\n";
            echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes without Phenotypes\" onClick=\"copyData('skip_form1')\"></td>\n";
            echo "<td>&nbsp;</td>\n";
            echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Select Phenotypes to Investigate\" onClick=\"copyData('skip_form1')\"></td>\n";
            echo "</tr>\n";
            echo "<tr><td>&nbsp;</td></tr>\n";
            echo "</form>\n\n";

            echo "<tr>\n";
	    echo "<form action=\"marker_search.php\" name=\"form\" method=\"POST\" target=\"main\">\n";
	    $records_left = ($num_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>&nbsp;</td>\n";
            echo "<td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Deselect Selections\"></td>\n";
            echo "</tr>\n";
	  }#end multiple pages
	else #only one page
	  {
            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=\"marker_record\">\n";
            echo "<input type=\"hidden\" name=\"marker_id\" value=\"\">\n";
            echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Marker Information\" onClick=\"copyData('download_form1')\"></td>\n";
            echo "<td>&nbsp;</td>\n";
            echo "</form>\n\n";

            echo "<form action=\"calculate_hardy_weinberg.php\" name=\"hwe_form1\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";
            echo "<input type=\"hidden\" name=\"how_to_select\" value=\"marker_search\">\n";
            echo "<input type=\"hidden\" name=\"marker_id\" value=\"\">\n";
            echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Calculate HWE for Marker(s)\" onClick=\"copyData('hwe_form1')\"></td>\n";
            echo "</tr>\n";
            echo "<tr><td>&nbsp;</td></tr>\n";
            echo "</form>\n\n";

	    echo "<form action=\"marker_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 to Investigate\"></td>\n";
            echo "</tr>\n";
            echo "<tr><td>&nbsp;</td><td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Deselect Selections\"></td></tr>\n";
	  }#end only one page of markers
        echo "</table>\n";
	echo "<br><br>\n";

	$jscript = printMarkerCheckList($marker_rec_list);
	if ($jscript == '0')
          {
	    $date = date('Y-m-d H:i:s');
	    echo "Error #259: $date<br>\n";
	    echo "Error in call to printMarkerCheckList from marker_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 "<input type=\"hidden\" name=\"status\" value=\"$status\">\n";
        echo "<input type=\"hidden\" name=\"marker_flag\" value=\"$marker_flag\">\n";
	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";
	      }#end else marker ids is an array
          }#end if have marker_ids

	echo "<br><br>\n";
	echo "<table align=\"center\">\n";
	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\" name=\"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 "<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>&nbsp;</td>\n";
            echo "<td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Deselect Selections\"></td>\n";
            echo "</tr>\n";
            echo "</form>\n\n";

            echo "<tr><td>&nbsp;</td></tr>\n";
            echo "<tr>\n";
            echo "<form action=\"marker_search.php\" name=\"skip_form2\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";
            echo "<input type=\"hidden\" name=\"status\" value=\"\">\n";
            echo "<input type=\"hidden\" name=\"marker_flag\" value=\"1\">\n";
            echo "<input type=\"hidden\" name=\"marker_multiple_pages\" value=\"0\">\n";
            echo "<input type=\"hidden\" name=\"marker_id\" value=\"\">\n";
            echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes without Phenotypes\" onClick=\"copyData('skip_form2')\"></td>\n";
            echo "<td>&nbsp;</td>\n";
            echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Select Phenotypes to Investigate\" onClick=\"copyData('skip_form2')\"></td>\n";
            echo "</tr>\n";
            echo "</form>\n\n";

            echo "<tr><td>&nbsp;</td></tr>\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=\"marker_record\">\n";
            echo "<input type=\"hidden\" name=\"marker_id\" value=\"\">\n";
            echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Marker Information\" onClick=\"copyData('download_form2')\"></td>\n";
            echo "<td>&nbsp;</td>\n";
            echo "</form>\n\n";

            echo "<form action=\"calculate_hardy_weinberg.php\" name=\"hwe_form2\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";
            echo "<input type=\"hidden\" name=\"how_to_select\" value=\"marker_search\">\n";
            echo "<input type=\"hidden\" name=\"marker_id\" value=\"\">\n";
            echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Calculate HWE for Marker(s)\" onClick=\"copyData('hwe_form2')\"></td>\n";
            echo "</tr>\n";
            echo "</form>\n\n";
	  }#end have multiple pages to display
	else #only have one page of markers to display
	  {
            echo "<tr><td>&nbsp;</td><td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Deselect Selections\"></td></tr>\n";
            echo "<tr><td>&nbsp;</td></tr>\n";
            echo "<tr>\n";
	    echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes without Phenotypes\"></td>\n";
            echo "<td>&nbsp;</td>\n";
	    echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Select Phenotypes to Investigate\"></td>\n";
            echo "</tr>\n";
            echo "</form>\n\n";

            echo "<tr><td>&nbsp;</td></tr>\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=\"marker_record\">\n";
            echo "<input type=\"hidden\" name=\"marker_id\" value=\"\">\n";
            echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Marker Information\" onClick=\"copyData('download_form2')\"></td>\n";
            echo "<td>&nbsp;</td>\n";
            echo "</form>\n\n";

            echo "<form action=\"calculate_hardy_weinberg.php\" name=\"hwe_form2\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";
            echo "<input type=\"hidden\" name=\"how_to_select\" value=\"marker_search\">\n";
            echo "<input type=\"hidden\" name=\"marker_id\" value=\"\">\n";
            echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Calculate HWE for Marker(s)\" onClick=\"copyData('hwe_form2')\"></td>\n";
            echo "</tr>\n";
            echo "</form>\n\n";
	  }
        echo "</table>\n";
	echo "<br>\n";

        $ret_val = printLogOutButton('marker_search.php');
	echo "\n\n";
		 
	echo "<script>\n";
	echo "function Validate(form)\n";
	echo "$jscript\n";
	echo "\n";
        echo "function copyData(formname)\n";
        echo "{\n";
        echo "  var marker_string = new Array();\n";
        echo "  var length = 0;\n";
        echo "  if (document.form.elements['marker_id[]'].length > 1){\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 "        if (document.form.elements['marker_id[]'][i].value != \"\"){\n";
        echo "          length = marker_string.length;\n";
        echo "          marker_string[length] = 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 "  else{\n";
        echo "    if (document.form.elements['marker_id[]'].type == \"hidden\"){\n";
        echo "      length = marker_string.length;\n";
        echo "      marker_string[length] = document.form.elements['marker_id[]'].value;}\n";
        echo "    else{\n";
        echo "      if (document.form.elements['marker_id[]'].checked){\n";
        echo "        length = marker_string.length;\n";
        echo "        marker_string[length] = document.form.elements['marker_id[]'].value;}}}\n";
        echo "  if (formname == 'hwe_form1'){\n";
        echo "    document.hwe_form1.marker_id.value = marker_string;}\n";
        echo "  if (formname == 'hwe_form2'){\n";
        echo "    document.hwe_form2.marker_id.value = marker_string;}\n";
        echo "  if (formname == 'skip_form1'){\n";
        echo "    document.skip_form1.status.value = document.form.status.value;\n";
        echo "    document.skip_form1.marker_id.value = marker_string;}\n";
        echo "  if (formname == 'skip_form2'){\n";
        echo "    document.skip_form2.status.value = document.form.status.value;\n";
        echo "    document.skip_form2.marker_id.value = marker_string;}\n";
        echo "  if (formname == 'download_form1'){\n";
        echo "    document.download_form1.marker_id.value = marker_string;}\n";
        echo "  if (formname == 'download_form2'){\n";
        echo "    document.download_form2.marker_id.value = marker_string;}\n";
        echo "}\n";
	echo "</script>\n";
        unset($marker_multiple_pages);
        unset($marker_flag);
      }#end if have seen markers, but still have pages to investigate

    if (($marker_flag == '1') and 
         ($marker_multiple_pages == '0') and 
         (sizeof($marker_ids) > '0') and
         (preg_match('/\w+/',$status))
       )#end if have seen all markers
      {
	#6	Print Phenotype CheckList
	if ((!preg_match('/\d/',$pheno_multiple_pages)) and
	    ($submit == 'Select Phenotypes to Investigate')
	   )#if want to investigate phenotypes, but haven't seen any yest
	  {
            echo "Please select which Phenotypes to Investigate:<br><br>\n";

	    $field_list_array = array('phenotype_id');
            $num_phenotypes = countTableQuery('phenotype_table',$database_id,$field_list_array,'_','wildcard');
            if (!preg_match('/^\d+$/',$num_phenotypes))
              {
                $date = date('Y-m-d H:i:s');
		echo "Error #260: $date<br>\n";
		echo "Error in call to countTableQuery from marker_search.php<br>\n";
		echo "$num_phenotypes<br><br>\n";
		echo "Please email the above error using the 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_phenotypes == '0')
              {
                $date = date('Y-m-d H:i:s');
                echo "Currently there are no phenotypes in the database.<br>\n";
                echo "This message was generated at $date.<br><br>\n";
                echo "Click the button below to select the individuals you would like to retieve \n";
                echo "data on for the markers you have selected.<br><br>\n";

                echo "<form action=\"marker_search.php\" name=\"form\" method=\"POST\" target=\"main\">\n";
                echo "<input type=\"hidden\" name=\"status\" value=\"$status\">\n";
                echo "<input type=\"hidden\" name=\"marker_flag\" value=\"$marker_flag\">\n";
	        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 "<center>\n";
                echo "<input type=\"submit\" name=\"submit\" value=\"Get Genotypes without Phenotypes\">\n";
                echo "</form>\n";
                echo "</center>\n";
	        echo "<br><br>\n";

	        $ret_val = printLogOutButton('marker_search.php');
                $ret_val = disconnect();
                exit;
              }#end if there aren't any phenotypes

            if ($num_phenotypes > ($max_records_to_print_per_page * 5))
              {
                echo "<br>\n";
                echo "<hr>\n";
                echo "<br>\n";
                echo "There are $num_phenotypes Phenotypes.  If you would like information on all the phenotypes, without selecting \n";
                echo "each one, click the button below:<br><br>\n";

                $pheno_id_array = distinctTableQuery('phenotype_id','phenotype_table',$database_id,$field_list_array,'_','wildcard','all','type_of_phenotype,phenotype_name');
	        if (!is_array($pheno_id_array))
	          {
		    $date = date('Y-m-d H:i:s');
		    echo "Error #261: $date<br>\n";
		    echo "Error in call to distinctTableQuery from marker_search.php<br>\n";
		    echo "$pheno_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
                $all_pheno_id_term = join($pheno_id_array,',');
                unset($pheno_id_array);

                echo "<table align=\"center\">\n";
                echo "<form action=\"marker_search.php\" name=\"skip_form\" method=\"POST\" target=\"main\">\n";
                echo "<input type=\"hidden\" name=\"pheno_id\" value=\"$all_pheno_id_term\">\n";
                echo "<input type=\"hidden\" name=\"pheno_multiple_pages\" value=\"0\">\n";
                echo "<input type=\"hidden\" name=\"marker_flag\" value=\"$marker_flag\">\n";
                echo "<input type=\"hidden\" name=\"marker_multiple_pages\" value=\"$marker_multiple_pages\">\n";
                echo "<input type=\"hidden\" name=\"status\" value=\"$status\">\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 more than one marker_id
                echo "<tr>\n";
                echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes and Phenotypes\"></td>\n";
                echo "</tr>\n";
                echo "</table>\n";
                echo "</form>\n";
                echo "<br>\n";
                echo "<hr>\n";
                echo "<br>\n";
                echo "Otherwise, continue below to select the Phenotypes you want information for.<br><br><br>\n";
                unset($all_pheno_id_term);
              }#end if more than 5 pages of records

            if ($num_phenotypes > $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,'type_of_phenotype,phenotype_name');
	        if (!is_array($pheno_rec_list))
	          {
		    $date = date('Y-m-d H:i:s');
		    echo "Error #262: $date<br>\n";
		    echo "Error in call to tableQuery from marker_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))
                $final_function_call    = 'tableQuery';
                $final_table_name       = 'phenotype_table';
                $final_field_list       = $field_list_array;
                $final_term             = '_';
                $final_mode             = 'wildcard';
                $final_order_by         = 'type_of_phenotype,phenotype_name';
                $last_record_retrieved = $max_records_to_print_per_page;
              }#end if more records than should be printed on one page
            else #only one page of phenotypes
              {
                $pheno_multiple_pages = 0;

                $pheno_rec_list = tableQuery('phenotype_table',$database_id,$field_list_array,'_','wildcard','all','type_of_phenotype,phenotype_name');
	        if (!is_array($pheno_rec_list))
	          {
		    $date = date('Y-m-d H:i:s');
		    echo "Error #263: $date<br>\n";
		    echo "Error in call to tableQuery from marker_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))
              }#end else only one page of phenotypes

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

            echo "<table align=\"center\">\n";
            if ($pheno_multiple_pages)
              {
                echo "<form action=\"marker_search.php\" name=\"skip_form1\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";
                echo "<input type=\"hidden\" name=\"pheno_id\" value=\"\">\n";
                echo "<input type=\"hidden\" name=\"pheno_multiple_pages\" value=\"0\">\n";
                echo "<input type=\"hidden\" name=\"marker_flag\" value=\"$marker_flag\">\n";
                echo "<input type=\"hidden\" name=\"marker_multiple_pages\" value=\"$marker_multiple_pages\">\n";
                echo "<input type=\"hidden\" name=\"status\" value=\"$status\">\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 more than one marker_id
                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=\"marker_search.php\" name=\"form\" method=\"POST\" target=\"main\">\n";
                $records_left = $num_phenotypes - $max_records_to_print_per_page;
                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 "<tr><td>&nbsp;</td></tr>\n";
                echo "<tr><td>&nbsp;</td><td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Reset Selections\"></td></tr>\n";
              }#end if multiple pages of phenotypes
            else #only a single page of phenotype
              {
                echo "<form action=\"marker_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 Selections\"></td>\n";
                echo "</tr>\n";
              }
	    echo "</table>\n";
            echo "<br><br>\n";

	    $jscript = printPhenotypeCheckList($pheno_rec_list);
	    if ($jscript == '0')
	      {
		$date = date('Y-m-d H:i:s');
		echo "Error #264: $date<br>\n";
		echo "Error in call to printPhenotypeCheckList from marker_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 "<input type=\"hidden\" name=\"status\" value=\"$status\">\n";
            echo "<input type=\"hidden\" name=\"marker_flag\" value=\"$marker_flag\">\n";
            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 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\" name=\"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";
              }#end if multiple pages of phenotypes

	    echo "<br>\n";
	    echo "<table align=\"center\">\n";
            if ($pheno_multiple_pages)
              {
                echo "<tr><td>&nbsp;</td><td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Reset Selections\"></td></tr>\n";
                echo "<tr><td>&nbsp;</td></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";}
              }#end if multiple pages of phenotypes
            else #only a single page of phenotype
              {
                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 Selections\"></td>\n";
                echo "</tr>\n";
              }
	    echo "</form>\n\n";

            if ($pheno_multiple_pages)
              {
                echo "<form action=\"marker_search.php\" name=\"skip_form2\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";
                echo "<input type=\"hidden\" name=\"pheno_id\" value=\"\">\n";
                echo "<input type=\"hidden\" name=\"pheno_multiple_pages\" value=\"0\">\n";
                echo "<input type=\"hidden\" name=\"marker_flag\" value=\"$marker_flag\">\n";
                echo "<input type=\"hidden\" name=\"marker_multiple_pages\" value=\"$marker_multiple_pages\">\n";
                echo "<input type=\"hidden\" name=\"status\" value=\"$status\">\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 more than one marker_id
                echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes and Phenotypes\" onClick=\"copyData('skip_form2')\"></td>\n";
                echo "</tr>\n";
                echo "</form>\n\n";
              }#end if multiple pages of phenotypes
            echo "</table>\n";
            echo "<br>\n";

            $ret_val = printLogOutButton('marker_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(formname)\n";
                echo "{\n";
                echo " var pheno_string = new Array();\n";
                echo " var length = 0;\n";
                echo " if (document.form.elements['pheno_id[]'].length > 1){\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 " else{\n";
                echo "   if (document.form.elements['pheno_id[]'].checked){\n";
                echo "     length = pheno_string.length;\n";
                echo "     pheno_string[length] = document.form.elements['pheno_id[]'].value;}}\n";
                echo " if (formname == \"skip_form1\"){\n";
                echo "   document.skip_form1.pheno_id.value = pheno_string;}\n";
                echo " if (formname == \"skip_form2\"){\n";
                echo "   document.skip_form2.pheno_id.value = pheno_string;}\n";
                echo "}\n";
              }#end if multiple pages of phenotype
	    echo "</script>\n";
            unset($pheno_multiple_pages);
	  }#end if want phenotypes but haven't seen any yet

        if (($pheno_multiple_pages == '1') and 
            (preg_match('/Get Next \d+ Phenotypes/',$submit))
           )#want phenotypes, but haven't seen all phenotypes yet
          {
            echo "Select the Phenotypes you want data for:<br><br>\n";

            if ($function_to_call == 'tableQuery')
              {
                $num_of_phenotypes = countTableQuery($table_name,$database_id,$field_list,$term,$mode);
	        if (!preg_match('/^\d+$/',$num_of_phenotypes))
	          {
		    $date = date('Y-m-d H:i:s');
		    echo "Error #265: $date<br>\n";
		    echo "Error in call to countTableQuery from marker_search.php<br>\n";
		    echo "$num_of_phenotypes<br><br>\n";
		    echo "Please email the above error using The 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_phenotypes - $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 #266: $date<br>\n";
		        echo "Error in call to tableQuery from marker_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 #267: $date<br>\n";
		        echo "Error in call to marker_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 one page of records
	        else #only one page of records
	          {
                    $pheno_multiple_pages = 0;
		    $from = $last_record_retrieved;
		    $to   = $num_of_phenotypes - 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 #268: $date<br>\n";
		        echo "Error in call to tableQuery from marker_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 #269: $date<br>\n";
		        echo "Error in call to marker_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 fit on one page
	      }#end if tableQuery

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

            echo "<table align=\"center\">\n";
	    if ($pheno_multiple_pages)
	      {
                echo "<form action=\"marker_search.php\" name=\"skip_form1\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";
                echo "<input type=\"hidden\" name=\"pheno_multiple_pages\" value=\"0\">\n";
                echo "<input type=\"hidden\" name=\"marker_flag\" value=\"$marker_flag\">\n";
                echo "<input type=\"hidden\" name=\"marker_multiple_pages\" value=\"$marker_multiple_pages\">\n";
                echo "<input type=\"hidden\" name=\"status\" value=\"$status\">\n";
                echo "<input type=\"hidden\" name=\"pheno_id[]\" value=\"\">\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 more than one marker_id
                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=\"marker_search.php\" name=\"form\" method=\"POST\" target=\"main\">\n";
	        $records_left = ($num_of_phenotypes - $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 "<tr><td>&nbsp;</td></tr>\n";
                echo "<tr><td>&nbsp;</td><td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Deselect Selections\"></td></tr>\n";
	      }#end multiple pages
	    else #only one page
	      {
	        echo "<form action=\"marker_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=\"Deselect Selections\"></td>\n";
                echo "</tr>\n";
	      }#end only one page of markers
            echo "</table>\n";
            echo "<br><br>\n";

	    $jscript = printPhenotypeCheckList($pheno_rec_list);
	    if ($jscript == '0')
              {
	        $date = date('Y-m-d H:i:s');
	        echo "Error #270: $date<br>\n";
	        echo "Error in call to printPhenotypeCheckList from marker_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 "<input type=\"hidden\" name=\"status\" value=\"$status\">\n";
            echo "<input type=\"hidden\" name=\"marker_flag\" value=\"$marker_flag\">\n";
	    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=\"$pheno_multiple_pages\">\n";
            if (sizeof($pheno_ids) > '0')#if have phenotype ids from previous page
              {
                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 phenotype ids from previous page

	    echo "<br><br>\n";
	    echo "<table align=\"center\">\n";
	    if ($pheno_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\" name=\"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 "<tr><td>&nbsp;</td><td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Deselect Selections\"></td></tr>\n";
                echo "<tr><td>&nbsp;</td></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";}
	      }#end have multiple pages to display
	    else #only have one page of markers to display
	      {
                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=\"Deselect Selections\"></td>\n";
                echo "</tr>\n";
	      }
	    echo "</form>\n\n";

            if ($pheno_multiple_pages)
              {
                echo "<form action=\"marker_search.php\" name=\"skip_form2\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";
                echo "<input type=\"hidden\" name=\"pheno_multiple_pages\" value=\"0\">\n";
                echo "<input type=\"hidden\" name=\"marker_flag\" value=\"$marker_flag\">\n";
                echo "<input type=\"hidden\" name=\"marker_multiple_pages\" value=\"$marker_multiple_pages\">\n";
                echo "<input type=\"hidden\" name=\"status\" value=\"$status\">\n";
                echo "<input type=\"hidden\" name=\"pheno_id[]\" value=\"\">\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 more than one marker_id
                echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes and Phenotypes\" onClick=\"copyData('skip_form2')\"></td>\n";
                echo "</tr>\n";
                echo "</form>\n\n";
              }#end if multiple pages of phenotypes
            echo "</table>\n";
	    echo "<br>\n";

            $ret_val = printLogOutButton('marker_search.php');
	    echo "\n\n";
		 
	    echo "<script>\n";
	    echo "function Validate(form)\n";
	    echo "$jscript\n";
	    echo "\n";
            if ($pheno_multiple_pages)
              {
                echo "\n";
                echo "function copyData(formname)\n";
                echo "{\n";
                echo " var pheno_string = new Array();\n";
                echo " var length = 0;\n";
                echo " if (document.form.elements['pheno_id[]'].length > 1){\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 "       if (document.form.elements['pheno_id[]'][i].value != \"\"){\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 " else{\n";
                echo "   if (document.form.elements['pheno_id[]'].type == \"hidden\"){\n";
                echo "     length = pheno_string.length;\n";
                echo "     pheno_string[length] = document.form.elements['pheno_id[]'].value;}\n";
                echo "   else{\n";
                echo "     if (document.form.elements['pheno_id[]'].checked){\n";
                echo "       length = pheno_string.length;\n";
                echo "       pheno_string[length] = document.form.elements['pheno_id[]'].value;}}}\n";
                echo " if (formname == \"skip_form1\"){\n";
                echo "   document.skip_form1.pheno_id.value = pheno_string;}\n";
                echo " if (formname == \"skip_form2\"){\n";
                echo "   document.skip_form2.pheno_id.value = pheno_string;}\n";
                echo "}\n";
              }#end if multiple pages of phenotype
	    echo "</script>\n";
            unset($pheno_multiple_pages);
          }#end if want phenotypes, but haven't seen all of them yet

        #7  Have status, all marker ids, and if want phenotypes phenotype ids; but haven't seen pedigrees
	if (((preg_match('/\w+/',$status)) and
	     (sizeof($marker_ids) > '0') and
             ($marker_multiple_pages == '0') and
	     ($submit == 'Get Genotypes without Phenotypes') and
             (!preg_match('/\d/',$ped_flag))
	    )or
	    ((preg_match('/\w+/',$status)) and
	     (sizeof($marker_ids) > '0') and
             ($marker_multiple_pages == '0') and
             ($pheno_multiple_pages == '0') and
	     (sizeof($pheno_ids) > '0') and
             (!preg_match('/\d/',$ped_flag))
	    )
	   )
	  {
            if ($submit == 'Get Genotypes without Phenotypes')
              {echo "Please select the Pedigrees that you want Genotypes for:\n";}
            else
              {echo "Please select the Pedigrees that you want Genotypes and Phenotype Values for :\n";}
            echo "<br><br>\n";

            $field_list_array = array('pedigree_table_id');
            $num_pedigrees = countTableQuery('pedigree_table',$database_id,$field_list_array,'_','wildcard');
            if (!preg_match('/^\d+$/',$num_pedigrees))
              {
                $date = date('Y-m-d H:i:s');
                echo "Error #271: $date<br>\n";
                echo "Error in call to countTableQuery from marker_search.php<br>\n";
                echo "$num_pedigrees<br><br>\n";
                echo "Please email the above error using the Comments/Help/Support link on the \n";
		echo "left navigation bar.\n";
		echo "</body></html>\n";
		$ret_val = disconnect();
		exit;
	      }#end if error in call to countTableQuery
            if ($num_pedigrees == '0')
              {
                $date = date('Y-m-d H:i:s');
                echo "Currently there are no pedigrees in the database.<br>\n";
                echo "Therefore there are no genotypes or phenotype values to download at this time.<br>\n";
                echo "This message was generated at $date.<br><br>\n";
                echo "Click the button below to return to the home page<br><br>\n";

                echo "<center>\n";
                echo "<form action=\"\" name=\"HOME\" method=\"POST\" target=\"\">\n";#don't know if this is correct???
                echo "<input type=\"button\" value=\"Home\" onClick=\"window.location='../right.html';\">\n";
                echo "</form>\n";
                echo "</center>\n";
	        echo "<br><br>\n";

	        $ret_val = printLogOutButton('marker_search.php');
                $ret_val = disconnect();
                exit;
              }#end if there aren't any pedigrees

            if ($num_pedigrees > ($max_records_to_print_per_page * 5))
              {
                echo "<br>\n";
                echo "<hr>\n";
                echo "<br>\n";
                echo "There are $num_pedigrees Pedigrees.  If you would like information on all the pedigrees, \n";
                echo "without selecting each one, click the button below:<br><br>\n";

                if ($db_type == 'mysql'){$order_by = 'nationality,pedigree_id+0';}
                if ($db_type == 'pgsql'){$order_by = "nationality,pedigree_id::text::integer";}
 	        $ped_id_array = distinctTableQuery('pedigree_table_id','pedigree_table',$database_id,$field_list_array,'_','wildcard','all',$order_by);
	        if (!is_array($ped_id_array))
	          {
		    $date = date('Y-m-d H:i:s');
		    echo "Error #272: $date<br>\n";
		    echo "Error in call to distinctTableQuery from marker_search.php<br>\n";
		    echo "$ped_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 distincTableQuery
                $all_ped_id_term = join($ped_id_array,',');
                unset($ped_id_array);

                echo "<table align=\"center\">\n";
                echo "<form action=\"marker_search.php\" name=\"skip_form\" method=\"POST\" target=\"main\">\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);
                      }
                    echo "<input type=\"hidden\" name=\"pheno_multiple_pages\" value=\"$pheno_multiple_pages\">\n";
                  }#end if have phenotype ids
                echo "<input type=\"hidden\" name=\"marker_flag\" value=\"$marker_flag\">\n";
                echo "<input type=\"hidden\" name=\"marker_multiple_pages\" value=\"$marker_multiple_pages\">\n";
                echo "<input type=\"hidden\" name=\"status\" value=\"$status\">\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 more than one marker_id
                echo "<input type=\"hidden\" name=\"ped_flag\" value=\"1\">\n";
                echo "<input type=\"hidden\" name=\"ped_multiple_pages\" value=\"0\">\n";
                echo "<input type=\"hidden\" name=\"ped_id\" value=\"all_ped_id_term\">\n";
                echo "<tr>\n";
                if (sizeof($pheno_ids) > '0')
                  {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Genotypes and Phenotypes\"></td>\n";}
                else
                  {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Genotypes\"></td>\n";}
                echo "</tr>\n";
                echo "</table>\n";
                echo "</form>\n";
                echo "<br>\n";
                echo "<hr>\n";
                echo "<br>\n";
                echo "Otherwise, continue below to select the Pedigrees you want information for.<br><br><br>\n";
                unset($all_ped_id_term);
              }#end if more than 5 pages of records

            if ($num_pedigrees > $max_records_to_print_per_page)
              {
                $ped_multiple_pages = 1;
                $from               = 0;
                $to                 = $max_records_to_print_per_page - 1;
                $range              = "$from"."-"."$to";
                if ($db_type == 'mysql'){$order_by = 'nationality,pedigree_id+0';}
                if ($db_type == 'pgsql'){$order_by = "nationality,pedigree_id::text::integer";}
 	        $ped_rec_list = tableQuery('pedigree_table',$database_id,$field_list_array,'_','wildcard',$range,$order_by);
	        if (!is_array($ped_rec_list))
	          {
		    $date = date('Y-m-d H:i:s');
		    echo "Error #273: $date<br>\n";
		    echo "Error in call to tableQuery from marker_search.php<br>\n";
		    echo "$ped_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(ped_rec_list))
                $final_function_call    = 'tableQuery';
                $final_table_name       = 'pedigree_table';
                $final_field_list       = $field_list_array;
                $final_term             = '_';
                $final_mode             = 'wildcard';
                $final_order_by         = $order_by;
                $last_record_retrieved = $max_records_to_print_per_page;
              }#end if more records than should be printed on one page
            else #only one page of phenotypes
              {
                $ped_multiple_pages = 0;
                if ($db_type == 'mysql'){$order_by = 'nationality,pedigree_id+0';}
                if ($db_type == 'pgsql'){$order_by = "nationality,pedigree_id::text::integer";}
                $ped_rec_list = tableQuery('pedigree_table',$database_id,$field_list_array,'_','wildcard','all',$order_by);
	        if (!is_array($ped_rec_list))
	          {
		    $date = date('Y-m-d H:i:s');
		    echo "Error #274: $date<br>\n";
		    echo "Error in call to tableQuery from marker_search.php<br>\n";
		    echo "$ped_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(ped_rec_list))
              }#end else only one page of pedigrees

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

            echo "<table align=\"center\">\n";
            if ($ped_multiple_pages)
              {
                echo "<form action=\"marker_search.php\" name=\"skip_form1\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\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);
                      }
                    echo "<input type=\"hidden\" name=\"pheno_multiple_pages\" value=\"$pheno_multiple_pages\">\n";
                  }#end if have phenotype ids
                echo "<input type=\"hidden\" name=\"marker_flag\" value=\"$marker_flag\">\n";
                echo "<input type=\"hidden\" name=\"marker_multiple_pages\" value=\"$marker_multiple_pages\">\n";
                echo "<input type=\"hidden\" name=\"status\" value=\"$status\">\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 more than one marker_id
                echo "<input type=\"hidden\" name=\"ped_flag\" value=\"1\">\n";
                echo "<input type=\"hidden\" name=\"ped_multiple_pages\" value=\"0\">\n";
                echo "<input type=\"hidden\" name=\"ped_id\" value=\"\">\n";
                echo "<tr>\n";
                if (sizeof($pheno_ids) > '0')
                  {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Genotypes and Phenotypes\" onClick=\"copyData('skip_form1')\"></td>\n";}
                else
                  {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Genotypes\" onClick=\"copyData('skip_form1')\"></td>\n";}
                echo "</form>\n\n";

                echo "<form action=\"marker_search.php\" name=\"form\" method=\"POST\" target=\"main\">\n";
                $records_left = $num_pedigrees - $max_records_to_print_per_page;
                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 Pedigrees\"></td>\n";}
                else
                  {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Next $records_left Pedigrees\"></td>\n";}
                echo "</tr>\n";
                echo "<tr><td>&nbsp;</td></tr>\n";
                echo "<tr><td>&nbsp;</td><td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Reset Selections\"></td></tr>\n";
              }#end if multiple pages of phenotypes
            else #only a single page of phenotype
              {
                echo "<form action=\"marker_search.php\" name=\"form\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(this))\">\n";
                echo "<tr>\n";
                if (sizeof($pheno_ids) > '0')
                  {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Genotypes and Phenotypes\"></td>\n";}
                else
                  {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Genotypes\"></td>\n";}
                echo "<td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Reset Selections\"></td>\n";
                echo "</tr>\n";
              }
	    echo "</table>\n";
            echo "<br><br>\n";

	    $jscript = printPedigreeCheckList($ped_rec_list,$database_id);
	    if ($jscript == '0')
	      {
		$date = date('Y-m-d H:i:s');
		echo "Error #275: $date<br>\n";
		echo "Error in call to printPedigreeCheckList from marker_search.php<br>\n";
		echo "See above error message from printPedigreeCheckList 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 "<input type=\"hidden\" name=\"status\" value=\"$status\">\n";
            echo "<input type=\"hidden\" name=\"marker_flag\" value=\"$marker_flag\">\n";
            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 more than one marker_id

            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);
                  }
                echo "<input type=\"hidden\" name=\"pheno_multiple_pages\" value=\"$pheno_multiple_pages\">\n";
              }#end if have phenotype ids

            echo "<input type=\"hidden\" name=\"ped_flag\" value=\"1\">\n";
            echo "<input type=\"hidden\" name=\"ped_multiple_pages\" value=\"$ped_multiple_pages\">\n";
            if ($ped_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\" name=\"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";
              }#end if multiple pages of pedigrees

	    echo "<br>\n";
	    echo "<table align=\"center\">\n";
            if ($ped_multiple_pages)
              {
                echo "<tr><td>&nbsp;</td><td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Reset Selections\"></td></tr>\n";
                echo "<tr><td>&nbsp;</td></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 Pedigrees\"></td>\n";}
                else
                  {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Next $records_left Pedigrees\"></td>\n";}
              }#end if multiple pages of pedigrees
            else #only a single page of pedigree
              {
                echo "<tr>\n";
                if (sizeof($pheno_ids) > '0')
                  {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Genotypes and Phenotypes\"></td>\n";}
                else
                  {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Genotypes\"></td>\n";}
                echo "<td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Reset Selections\"></td>\n";
                echo "</tr>\n";
              }
	    echo "</form>\n\n";

            if ($ped_multiple_pages)
              {
                echo "<form action=\"marker_search.php\" name=\"skip_form2\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\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);
                      }
                    echo "<input type=\"hidden\" name=\"pheno_multiple_pages\" value=\"$pheno_multiple_pages\">\n";
                  }#end if have phenotypes
                echo "<input type=\"hidden\" name=\"status\" value=\"$status\">\n";
                echo "<input type=\"hidden\" name=\"marker_flag\" value=\"$marker_flag\">\n";
                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 more than one marker_id
                echo "<input type=\"hidden\" name=\"ped_flag\" value=\"1\">\n";
                echo "<input type=\"hidden\" name=\"ped_multiple_pages\" value=\"0\">\n";
                echo "<input type=\"hidden\" name=\"ped_id[]\" value=\"\">\n";
                if (sizeof($pheno_ids) > '0')
                  {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Genotypes and Phenotypes\" onClick=\"copyData('skip_form2')\"></td>\n";}
                else
                  {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Genotypes\" onClick=\"copyData('skip_form2')\"></td>\n";}
                echo "</tr>\n";
                echo "</form>\n\n";
              }#end if multiple pages of phenotypes
            echo "</table>\n";
            echo "<br>\n";

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

	    echo "<script>\n";
	    echo "function Validate(form)\n";
	    echo "$jscript\n";
            if ($ped_multiple_pages)
              {
                echo "\n";
                echo "function copyData(formname)\n";
                echo "{\n";
                echo " var ped_string = new Array();\n";
                echo " var length = 0;\n";
                echo " if (document.form.elements['ped_id[]'].length > 1){\n";
                echo "   for (var i=0; i<document.form.elements['ped_id[]'].length; i++){\n";
                echo "     if (document.form.elements['ped_id[]'][i].checked){\n";
                echo "       length = ped_string.length;\n";
                echo "       ped_string[length] = document.form.elements['ped_id[]'][i].value;}}}\n";
                echo " else{\n";
                echo "   if (document.form.elements['ped_id[]'].checked){\n";
                echo "     length = ped_string.length;\n";
                echo "     ped_string[length] = document.form.elements['ped_id[]'].value;}}\n";
                echo " if (formname == \"skip_form1\"){\n";
                echo "   document.skip_form1.ped_id.value = ped_string;}\n";
                echo " if (formname == \"skip_form2\"){\n";
                echo "   document.skip_form2.ped_id.value = ped_string;}\n";
                echo "}\n";
              }#end if multiple pages of pedigrees
	    echo "</script>\n";
            unset($ped_multiple_pages);
          }#end if have status,all marker_ids, and if want phenotypes phenotype ids; but haven't selected pedigrees

        if (((preg_match('/\w+/',$status)) and
	     (sizeof($marker_ids) > '0') and
             ($marker_multiple_pages == '0') and
	     ($ped_flag == '1') and
             ($ped_multiple_pages == '1')
	    )or
	    ((preg_match('/\w+/',$status)) and
	     (sizeof($marker_ids) > '0') and
             ($marker_multiple_pages == '0') and
             ($pheno_multiple_pages == '0') and
	     (sizeof($pheno_ids) > '0') and
             ($ped_flag == '1') and
             ($ped_multiple_pages == '1')
	    )
	   )#if have seen pedigrees, but still have more pedigrees to see
	  {
            echo "Select the Pedigrees you want data for:<br><br>\n";

            if ($function_to_call == 'tableQuery')
              {
                $num_of_pedigrees = countTableQuery($table_name,$database_id,$field_list,$term,$mode);
	        if (!preg_match('/^\d+$/',$num_of_pedigrees))
	          {
		    $date = date('Y-m-d H:i:s');
		    echo "Error #276: $date<br>\n";
		    echo "Error in call to countTableQuery from marker_search.php<br>\n";
		    echo "$num_of_pedigrees<br><br>\n";
		    echo "Please email the above error using The 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_pedigrees - $last_record_retrieved;

	        if ($records_yet_to_be_retrieved > $max_records_to_print_per_page)
	          {
                    $ped_multiple_pages = 1;
		    $from = $last_record_retrieved;
		    $to   = ($last_record_retrieved-1) + $max_records_to_print_per_page;
		    $range = "$from"."-"."$to";
		    $ped_rec_list = tableQuery($table_name,$database_id,$field_list,$term,$mode,$range,$order_by);
		    if (!is_array($ped_rec_list))
		      {
		        $date = date('Y-m-d H:i:s');
		        echo "Error #277: $date<br>\n";
		        echo "Error in call to tableQuery from marker_search.php<br>\n";
		        echo "$ped_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(ped_rec_list))
		    if (sizeof($ped_rec_list) == 0)
		      {
		        $date = date('Y-m-d H:i:s');
		        echo "Error #278: $date<br>\n";
		        echo "Error in call to marker_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 100 indivs left
	        else #100 or fewer indivs left
	          {
                    $ped_multiple_pages = 0;
		    $from = $last_record_retrieved;
		    $to   = $num_of_pedigrees - 1;
		    $range = "$from"."-"."$to";
		    $ped_rec_list = tableQuery($table_name,$database_id,$field_list,$term,$mode,$range,$order_by);
		    if (!is_array($ped_rec_list))
		      {
		        $date = date('Y-m-d H:i:s');
		        echo "Error #279: $date<br>\n";
		        echo "Error in call to tableQuery from marker_search.php<br>\n";
		        echo "$ped_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(ped_rec_list))
		    if (sizeof($ped_rec_list) == 0)
		      {
		        $date = date('Y-m-d H:i:s');
		        echo "Error #280: $date<br>\n";
		        echo "Error in call to marker_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 fit on one page
	      }#end if tableQuery

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

            echo "<table align=\"center\">\n";
	    if ($records_yet_to_be_retrieved > $max_records_to_print_per_page)
	      {
                echo "<form action=\"marker_search.php\" name=\"skip_form1\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(form))\">\n";
                echo "<input type=\"hidden\" name=\"marker_flag\" value=\"$marker_flag\">\n";
                echo "<input type=\"hidden\" name=\"marker_multiple_pages\" value=\"$marker_multiple_pages\">\n";
                echo "<input type=\"hidden\" name=\"status\" value=\"$status\">\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 more than one marker_id
                if (sizeof($pheno_ids) > '0')#if have phenotypes
                  {
                    echo "<input type=\"hidden\" name=\"pheno_multiple_pages\" value=\"$pheno_multiple_pages\">\n";
                    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 phenotypes
                echo "<input type=\"hidden\" name=\"ped_flag\" value=\"$ped_flag\">\n";
                echo "<input type=\"hidden\" name=\"ped_multiple_pages\" value=\"0\">\n";
                echo "<input type=\"hidden\" name=\"ped_id[]\" value=\"\">\n";
                echo "<tr>\n";
                if (sizeof($pheno_ids) > '0')
                  {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Genotypes and Phenotypes\" onClick=\"copyData('skip_form1')\"></td>\n";}
                else
                  {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Genotypes\" onClick=\"copyData('skip_form1')\"></td>\n";}
                echo "</form>\n\n";

	        echo "<form action=\"marker_search.php\" name=\"form\" method=\"POST\" target=\"main\">\n";
	        $records_left = ($num_of_pedigrees - $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 Pedigrees\"></td>\n";}
	        else
                  {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Next $records_left Pedigrees\"></td>\n";}
                echo "</tr>\n";
                echo "<tr><td>&nbsp;</td></tr>\n";
                echo "<tr><td>&nbsp;</td><td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Deselect Selections\"></td></tr>\n";
	      }#end multiple pages
	    else #only one page
	      {
	        echo "<form action=\"marker_search.php\" name=\"form\" method=\"POST\" target=\"main\" onSubmit=\"return(Validate(this))\">\n";
                echo "<tr>\n";
	        if (sizeof($pheno_ids) > '0')
                  {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Genotypes and Phenotypes\"></td>\n";}
                else
                  {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Genotypes\"></td>\n";}
                echo "<td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Deselect Selections\"></td>\n";
                echo "</tr>\n";
	      }#end only one page of markers
            echo "</table>\n";
            echo "<br><br>\n";

	    $jscript = printPedigreeCheckList($ped_rec_list,$database_id);
	    if ($jscript == '0')
              {
	        $date = date('Y-m-d H:i:s');
	        echo "Error #281: $date<br>\n";
	        echo "Error in call to printPedigreeCheckList from marker_search.php<br>\n";
	        echo "See above error message from printPedigreeCheckList 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 "<input type=\"hidden\" name=\"status\" value=\"$status\">\n";
            echo "<input type=\"hidden\" name=\"marker_flag\" value=\"$marker_flag\">\n";
	    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
            if (sizeof($pheno_ids) > '0')#if have phenotype ids from previous page
              {
                echo "<input type=\"hidden\" name=\"pheno_multiple_pages\" value=\"$pheno_multiple_pages\">\n";
                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 phenotype ids from previous page
            echo "<input type=\"hidden\" name=\"ped_flag\" value=\"$ped_flag\">\n";
            echo "<input type=\"hidden\" name=\"ped_multiple_pages\" value=\"$ped_multiple_pages\">\n";
            if (sizeof($ped_ids) > '0')#if have pedigrees from previous page(s)
              {
                if (!is_array($ped_ids)){echo "<input type=\"hidden\" name=\"ped_id[]\" value=\"$ped_ids\">\n";}
                else
                  {
                    $ped_id_string = join($ped_ids,',');
                    echo "<input type=\"hidden\" name=\"ped_id[]\" value=\"$ped_id_string\">\n";
                    unset($ped_id_string);
                  }
              }#end if have pedigrees from previous page(s)

            echo "<br><br>\n";
	    echo "<table align=\"center\">\n";
	    if ($ped_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\" name=\"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 "<tr><td>&nbsp;</td><td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Deselect Selections\"></td></tr>\n";
                echo "<tr><td>&nbsp;</td></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 Pedigrees\"></td>\n";}
	        else
                  {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Next $records_left Pedigrees\"></td>\n";}
	      }#end have multiple pages to display
	    else #only have one page of markers to display
	      {
                echo "<tr>\n";
	        if (sizeof($pheno_ids) > '0')
                  {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Genotypes and Phenotypes\"></td>\n";}
                else
                  {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Genotypes\"></td>\n";}
                echo "<td align=\"center\"><input type=\"reset\" name=\"reset\" value=\"Deselect Selections\"></td>\n";
                echo "</tr>\n";
	      }
	    echo "</form>\n\n";

            if ($ped_multiple_pages)
              {
                echo "<form action=\"marker_search.php\" name=\"skip_form2\" method=\"POST\" target=\"main\">\n";# onSubmit=\"return(Validate(form))\">\n";
                echo "<input type=\"hidden\" name=\"marker_flag\" value=\"$marker_flag\">\n";
                echo "<input type=\"hidden\" name=\"marker_multiple_pages\" value=\"$marker_multiple_pages\">\n";
                echo "<input type=\"hidden\" name=\"status\" value=\"$status\">\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 more than one marker_id
                if (sizeof($pheno_ids) > '0')
                  {
                    echo "<input type=\"hidden\" name=\"pheno_multiple_pages\" value=\"0\">\n";
                    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 phenotypes
                echo "<input type=\"hidden\" name=\"ped_flag\" value=\"$ped_flag\>\n";
                echo "<input type=\"hidden\" name=\"ped_multiple_pages\" value=\"0\">\n";
                echo "<input type=\"hidden\" name=\"ped_id[]\" value=\"\">\n";
                if (sizeof($pheno_ids) > '0')
                  {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Genotypes and Phenotypes\" onClick=\"copyData('skip_form2')\"></td>\n";}
                else
                  {echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Genotypes\" onClick=\"copyData('skip_form2')\"></td>\n";}
                echo "</tr>\n";
                echo "</form>\n\n";
              }#end if multiple pages of phenotypes
            echo "</table>\n";
	    echo "<br>\n";

            $ret_val = printLogOutButton('marker_search.php');
	    echo "\n\n";
		 
	    echo "<script>\n";
	    echo "function Validate(form)\n";
	    echo "$jscript\n";
	    echo "\n";
            if ($ped_multiple_pages)
              {
                echo "\n";
                echo "function copyData(formname)\n";
                echo "{\n";
                echo " var ped_string = new Array();\n";
                echo " var length = 0;\n";
                echo " if (document.form.elements['ped_id[]'].length > 1){\n";
                echo "   for (var i=0; i<document.form.elements['ped_id[]'].length; i++){\n";
                echo "     if (document.form.elements['ped_id[]'][i].type == \"hidden\"){\n";
                echo "       if (document.form.elements['ped_id[]'][i].value != \"\"){\n";
                echo "         length = ped_string.length;\n";
                echo "         ped_string[length] = document.form.elements['ped_id[]'][i].value;}}\n";
                echo "     else{\n";
                echo "       if (document.form.elements['ped_id[]'][i].checked){\n";
                echo "         length = ped_string.length;\n";
                echo "         ped_string[length] = document.form.elements['ped_id[]'][i].value;}}}}\n";
                echo " else{\n";
                echo "   if (document.form.elements['ped_id[]'].type == \"hidden\"){\n";
                echo "     length = ped_string.length;\n";
                echo "     ped_string[length] = document.form.elements['ped_id[]'].value;}\n";
                echo "   else{\n";
                echo "     if (document.form.elements['ped_id[]'].checked){\n";
                echo "       length = ped_string.length;\n";
                echo "       ped_string[length] = docuement.form.elements['ped_id[]'].value;}}}\n";
                echo " if (formname == \"skip_form1\"){\n";
                echo "   document.skip_form1.ped_id.value = ped_string;}\n";
                echo " if (formname == \"skip_form2\"){\n";
                echo "   document.skip_form2.ped_id.value = ped_string;}\n";
                echo "}\n";
              }#end if multiple pages of pedigrees
	    echo "</script>\n";
            unset($ped_multiple_pages);
          }#end if haven't seen all the pedigrees want to look at

        #Have all the information, but haven't selected if want analysis files
        if (((preg_match('/\w+/',$status)) and
	     (sizeof($marker_ids) > '0') and
             ($marker_multiple_pages == '0') and
	     ($ped_flag == '1') and
             ($ped_multiple_pages == '0') and
             (sizeof($ped_ids) > '0') and
             (!preg_match('/\d/',$create_analysis_files))
	    )or
            ((preg_match('/\w+/',$status)) and
	     (sizeof($marker_ids) > '0') and
             ($marker_multiple_pages == '0') and
             ($pheno_multiple_pages == '0') and
	     (sizeof($pheno_ids) > '0') and
             ($ped_flag == '1') and
             ($ped_multiple_pages == '0') and
             (sizeof($ped_ids) > '0') and
             (!preg_match('/\d/',$create_analysis_files))
	    )
           )
          {
            echo "<form action=\"marker_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=\"status\" value=\"$status\">\n";
            echo "<input type=\"hidden\" name=\"marker_flag\" value=\"$marker_flag\">\n";
	    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
            if (sizeof($pheno_ids) > '0')#if have phenotype ids from previous page
              {
                echo "<input type=\"hidden\" name=\"pheno_multiple_pages\" value=\"$pheno_multiple_pages\">\n";
                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 phenotype ids from previous page
            echo "<input type=\"hidden\" name=\"ped_flag\" value=\"$ped_flag\">\n";
            echo "<input type=\"hidden\" name=\"ped_multiple_pages\" value=\"$ped_multiple_pages\">\n";
            if (!is_array($ped_ids)){echo "<input type=\"hidden\" name=\"ped_id[]\" value=\"$ped_ids\">\n";}
            else
              {
                $ped_id_string = join($ped_ids,',');
                echo "<input type=\"hidden\" name=\"ped_id[]\" value=\"$ped_id_string\">\n";
                unset($ped_id_string);
              }

            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('marker_search.php');
          }#end if Have all the information, but haven't selected if 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
	     ($ped_flag == '1') and
             ($ped_multiple_pages == '0') and
             (sizeof($ped_ids) > '0') 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
             ($pheno_multiple_pages == '0') and
	     (sizeof($pheno_ids) > '0') and
             ($ped_flag == '1') and
             ($ped_multiple_pages == '0') and
             (sizeof($ped_ids) > '0') and
             ($create_analysis_files == '1') and
             (!preg_match('/\d+/',$analysis_option))
	    )
           )
          {
            echo "<form action=\"marker_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 #282: $date<br><br>\n";
                echo "Error in call to printMega2Form from marker_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=\"status\" value=\"$status\">\n";
            echo "<input type=\"hidden\" name=\"marker_flag\" value=\"$marker_flag\">\n";
	    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
            if (sizeof($pheno_ids) > '0')#if have phenotype ids from previous page
              {
                echo "<input type=\"hidden\" name=\"pheno_multiple_pages\" value=\"$pheno_multiple_pages\">\n";
                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 phenotype ids from previous page
            echo "<input type=\"hidden\" name=\"ped_flag\" value=\"$ped_flag\">\n";
            echo "<input type=\"hidden\" name=\"ped_multiple_pages\" value=\"$ped_multiple_pages\">\n";
            if (!is_array($ped_ids)){echo "<input type=\"hidden\" name=\"ped_id[]\" value=\"$ped_ids\">\n";}
            else
              {
                $ped_id_string = join($ped_ids,',');
                echo "<input type=\"hidden\" name=\"ped_id[]\" value=\"$ped_id_string\">\n";
                unset($ped_id_string);
              }

            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('marker_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

        #Have all the information, query the database and get data
        if (((preg_match('/\w+/',$status)) and
	     (sizeof($marker_ids) > '0') and
             ($marker_multiple_pages == '0') and
	     ($ped_flag == '1') and
             ($ped_multiple_pages == '0') and
             (sizeof($ped_ids) > '0') and
             ($create_analysis_files == '0')
	    )or
            ((preg_match('/\w+/',$status)) and
	     (sizeof($marker_ids) > '0') and
             ($marker_multiple_pages == '0') and
	     ($ped_flag == '1') and
             ($ped_multiple_pages == '0') and
             (sizeof($ped_ids) > '0') 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
             ($pheno_multiple_pages == '0') and
	     (sizeof($pheno_ids) > '0') and
             ($ped_flag == '1') and
             ($ped_multiple_pages == '0') and
             (sizeof($ped_ids) > '0') and
             ($create_analysis_files == '0')
	    ) or
            ((preg_match('/\w+/',$status)) and
	     (sizeof($marker_ids) > '0') and
             ($marker_multiple_pages == '0') and
             ($pheno_multiple_pages == '0') and
	     (sizeof($pheno_ids) > '0') and
             ($ped_flag == '1') and
             ($ped_multiple_pages == '0') and
             (sizeof($ped_ids) > '0') and
             ($create_analysis_files == '1') and
             (preg_match('/\d+/',$analysis_option))
	    )
	   )#if have all the required data, now process and prepare for download
	  {
            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 #283: $date<br>\n";
                echo "Error in call to fopen from marker_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($ped_ids)){$ped_term = $ped_ids;}
            else                    {$ped_term = join($ped_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('pedigree_table_id');
            $indiv_table_id_array = distinctTableQuery('individual_table_id','individual_table',$database_id,$field_list_array,$ped_term,'in','all','pedigree_id,individual_id');
            if (!is_array($indiv_table_id_array))
              {
                $date = date('Y-m-d H:i:s');
                echo "Error #284: $date<br>\n";
                echo "Error in call to distinctTableQuery from marker_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')
              {
                $date = date('Y-m-d H:i:s');
                echo "There are no individuals in the database for the pedigrees you selected.<br>\n";
                echo "Therefore there are no genotypes and phenotypes in the database to be downloaded.<br>\n";
                echo "This message was generated at $date.<br><br>\n";
                echo "Click the button below to return to the home page<br><br>\n";

                echo "<form action=\"\" name=\"HOME\" method=\"POST\" target=\"\">\n";#don't know if this is correct???
                echo "<input type=\"button\" value=\"Home\" onClick=\"window.location='../right.html';\">\n";
                echo "</form>\n";
                echo "</center>\n";
	        echo "<br><br>\n";

	        $printLogOutButton('marker_search.php');
                $ret_val = disconnect();
                exit;
              }#end if there aren't any individuals in the pedigrees selected
            $num_of_indivs = sizeof($indiv_table_id_array);
            $indiv_term = join($indiv_table_id_array,',');
            unset($indiv_table_id_array);

            $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 #285: $date<br>\n";
                echo "Error in call to countTableQuery from marker_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 #286: $date<br>\n";
                    echo "Error in call to countTableQuery from marker_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 #287: $date<br>\n";
                echo "Error in call to fwrite from marker_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 #288: $date<br>\n";
                echo "Error in call to fclose from marker_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 #289: $date<br>\n";
                echo "Error in call to chdir from marker_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]'  'Marker 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 running in background
            else #running in foreground
              {
                passthru($command,$sys_ret_val);
              }#end else running in foreground

            $ret_val = chdir("../../cgi-bin/");
            if (!$ret_val)
              {
                $date = date('Y-m-d H:i:s');
                echo "Error #290: $date<br>\n";
                echo "Error in call to chdir from marker_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 #291: $date<br>\n";
	        echo "Error in system call to query_and_write_results.pl<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('marker_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 all information and ready to download data
      }#end if marker_flag and no more markers left to see
  }#end if (auth_user == '1')
 $ret_val = disconnect();		    
 echo "</body></html>\n";

function tooManyMarkers()
{
  $marker_id_list = func_get_arg(0);

  echo "This number of markers 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 markers returned or get genotype information for all \n";
  echo "the markers 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=\"marker_record\">\n";
  echo "<input type=\"hidden\" name=\"marker_id\" value=\"$marker_id_list\">\n";
  echo "<tr>\n";
  echo "<td><input type=\"submit\" name=\"submit\" value=\"Download All Markers' Information\"></td>\n";
  echo "</form>\n";

  echo "<form action=\"marker_search.php\" name=\"form3\" method=\"POST\" target=\"main\">\n";
  echo "<input type=\"hidden\" name=\"marker_flag\" value=\"1\">\n";
  echo "<input type=\"hidden\" name=\"marker_multiple_pages\" value=\"0\">\n";
  echo "<input type=\"hidden\" name=\"marker_id\" value=\"$marker_id_list\">\n";
  echo "<td><input type=\"submit\" name=\"submit3\" value=\"Get Genotypes for All Markers\"></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 \"Marker Search\" tool.<br>\n";
  echo "</body>\n";
  echo "</html>\n";
}#end function tooManyMarkers

function moreThanFivePages()
{
  $marker_id_list = func_get_arg(0);
  global $database_id;

  echo "<br><br>\n";
  echo "<hr>\n";
  echo "<br>\n";
  echo "If would like to analyze all the markers returned by your search,<br>\n";
  echo "without investigating each one, select an Affection status to analyze and click the appropriate button below:<br><br>\n";

  echo "<table align=\"center\">\n";
  echo "<tr>\n";
  echo "<form action=\"download.php\" name=\"download_form\" method=\"POST\" target=\"main\">\n";
  echo "<input type=\"hidden\" name=\"type_of_download\" value=\"marker_record\">\n";
  echo "<input type=\"hidden\" name=\"marker_id\" value=\"$marker_id_list\">\n";
  echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Download Marker Information\"></td>\n";
  echo "<td>&nbsp;</td>\n";
  echo "</form>\n\n";

  echo "<form action=\"calculate_hardy_weinberg.php\" name=\"hwe_form\" method=\"POST\" target=\"main\">\n";
  echo "<input type=\"hidden\" name=\"how_to_select\" value=\"marker_search\">\n";
  echo "<input type=\"hidden\" name=\"marker_id\" value=\"$marker_id_list\">\n";
  echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Calculate HWE for Marker(s)\"></td>\n";
  echo "</tr>\n";
  echo "<tr><td>&nbsp;</td></tr>\n";
  echo "</form>\n\n";

  echo "<tr>\n";
  echo "<form action=\"marker_search.php\" name=\"skip_form\" method=\"POST\" target=\"main\" onSubmit=\"return(skipValidate1(skip_form))\">\n";
  echo "<input type=\"hidden\" name=\"marker_flag\" value=\"1\">\n";
  echo "<input type=\"hidden\" name=\"marker_multiple_pages\" value=\"0\">\n";
  echo "<input type=\"hidden\" name=\"marker_id\" value=\"$marker_id_list\">\n";
  echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Get Genotypes without Phenotypes\"></td>\n";
  echo "<td>&nbsp;</td>\n";
  echo "<td align=\"center\"><input type=\"submit\" name=\"submit\" value=\"Select Phenotypes to Investigate\"></td>\n";
  echo "</tr>\n";
  echo "<tr><td>&nbsp;</td><td><b>Affection Status:</b>\n";
  $skip_jscript = printStatusSelectList($database_id);
  if ($skip_jscript == '0')
    {
      $date = date('Y-m-d H:i:s');
      echo "Error #292: $date<br>\n";
      echo "Error in call to printStatusSelectList from marker_search.php<br>\n";
      echo "See above error from printStatusSelectList 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 error in call to printStatusSelectList
  if ($skip_jscript == 'no_defined_statuses')
    {
      $date = date('Y-m-d H:i:s');
      echo "This message was generated at $date.<br><br>\n";
      echo "Continue without selecting a status.<br>\n";
      echo "<input type=\"hidden\" name=\"status\" value=\"no_defined_statuses\">\n";
    }#end if no statuses to select
  echo "</form>\n";
  echo "</table>\n";

  echo "<script>\n";
  echo "function skipValidate1(form)\n";
  if ($skip_jscript == 'no_defined_statuses'){echo "{return true;}\n";}
  else                                       {echo "$skip_jscript\n";}
  echo "</script>\n";

  echo "<br>\n";
  echo "<hr>\n";
  echo "<br>\n";
  echo "Otherwise, continue below to select the markers you would like information for.<br><br><br>\n\n\n";
}#end function moreThanFivePages

?>
Return current item: Generic Genetic Studies Database