<?php

  require '../conf/config.php';
  require './common.php';

  //////////////////////////////////  Connecting with DB
  if( !$conn = new mysqli($host, $user, $pswd, $db)) {
    error_log("Connection failed.\n");
    exit;
  }

  ////////////////////////////////// prepare 
  (isset($_POST['phenoname']) && !empty($_POST['phenoname'])) ? $phenoname=$_POST['phenoname']:returnError("Error");
  _pregMatch($phenoname);
  $phenotypes = array();
  $str="";
  
  //$str="[";
  $queryA = "SELECT phenotype_id FROM sys_phenotype where phenotype = ?";
  $stmtA = $conn->stmt_init();
  $stmtA->prepare($queryA);
  $stmtA->bind_param("s",$phenoname);
  $stmtA->execute();
  $stmtA->store_result();
  $stmtA->bind_result($row0);
  while ($stmtA->fetch()) {
        $phenoid .= $row0;
  }

  $queryP = "SELECT accession_id, expression FROM sys_phenotype_expression where phenotype_id = ? order by expression";
  $stmtP = $conn->stmt_init();
  $stmtP->prepare($queryP);
  $stmtP->bind_param("s",$phenoid);
  $stmtP->execute();
  $stmtP->store_result();
  $stmtP->bind_result($row0,$row1);
  
  while ($stmtP->fetch()) {
	$str .= $row0.','.$row1.'|';
  	//$phenotypes[$row0] = $row1;
  }
  $stmtP->close();
  $str = rtrim($str, '|');
  //$str=$str."]";
/* 
  foreach($phenotypes as $phenotype_id => $phenotype) {
  	$str .= '{"phenotype":"' .$phenotype. '"},';
  }
  $str = rtrim($str, ',');
  $str=$str."]";
*/
  echo $str;
?>

