<?php
/*
* snpblock.php
* http://tasuke.dna.affrc.go.jp/
*
* Author: Ryutaro Itoh
*
* Copyright (c) 2013 National Institute of Agrobiological Sciences   
*
* This software is released under the MIT License.
*
* http://opensource.org/licenses/mit-license.php
*/

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

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

(isset($_GET['prm_accession']) && !empty($_GET['prm_accession'])) ? $prm_accession=$_GET['prm_accession']:returnError("Error");
$prm_accession = $conn->real_escape_string($prm_accession);

////////////////////////////////////////////////////////// List of accessions
$ids = array();
$rates = array();
$param1="%".$prm_accession."%"

$query = "SELECT accession, rate FROM sys_snpblock where accession like ? ";
$stmt = $conn->stmt_init();
$stmt->prepare($query);
$stmt->bind_param("s", $param1); 
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($row0,$row1);
while ($stmt->fetch()) {
    ids[]=$row0;
    $rates[]=$row1;
}
$stmt->free_result();
$stmt->close();
mysqli_close($conn);

$str="[";
for ($i=0; $i<count($ids); $i++) {
    $str=$str."{\"id\":\"".$ids[$i]."\",\"rate\":\"".$rates[$i]."\"}"; 
    if ( $i<count($ids)-1 ) {
        $str=$str.",";
    }
}
$str=$str."]";
echo $str;
?>

