php 联合选择不同的问题

标签 php mysql docker-compose

我提交了这两个文件:

我在下一页上收到以下错误:

304501820180500000018.304501820180500000018<br><br>select distinct org1,org2 from '.304501820180500000018.'_synteny union select distinct org1,org2 from '.304501820180500000018.'_synteny<br><br>

Invalid query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''.304501820180500000018.'_synteny union select distinct org1,org2 from '.3045018' at line 1

Whole query: select distinct org1,org2 from '.304501820180500000018.'_synteny union select distinct org1,org2 from '.304501820180500000018.'_synteny[]

mGSV/lib/data.php 如下所示并导致上述错误:

<?php
include('database.php');

## Get parameters
$org = $_GET['org'];
$data = $_GET['data'];
$session_id = $_GET['session_id'];

$array = array();

if($data == 'annotation') {
    $query = "SELECT track_name FROM ".$session_id."_annotation WHERE org_id like '$org' GROUP BY track_name ";
    $result = mysql_query($query);

    if($result != ''){
        while($row = mysql_fetch_assoc($result)){
            array_push($array, $row['track_name']);
        }
    }
    //array_push($syn_array, "10_50_20_70");
}
else if ($data == 'synteny') {
    $query = "DESC ".$session_id."_synteny";
    $result = mysql_query($query);
    while($row = mysql_fetch_assoc($result)){
        if($row['Field'] == 'id'){ continue; }
        if($row['Field'] == 'blocks'){ continue; }
        if($row['Field'] == 'SYNcolor'){ continue; }
        if(! preg_match("/^org[12]+[_]?[start|end]?/", $row['Field'])){
            array_push($array, $row['Field']);
        }
    }
}
else if ($data == 'size'){
    echo "$session_id.", $session_id, "<br>";
    echo "$org", $org, "<br>";
    $query = "select distinct org1,org2 from '.$session_id.'_synteny union select distinct org1,org2 from '.$session_id.'_synteny";
    echo $query,"<br>";
    $result = mysql_query($query);
    echo $results,"<br>";
    if ($results) {
        while($row = mysql_fetch_assoc($result)){
            echo $row['org1'], "<br>";
            $q = "select max(output) as max from (select max(greatest(org1_start, org1_end)) as output from ".$session_id."_synteny where org1 like '" . $row['org1'] . "' union select max(greatest(org2_start, org2_end)) as output from ".$session_id."_synteny where org2 like '" . $row['org1'] . "') as t1";
            echo $q, "<br>";
            $res = mysql_query($q);
            if (!$res) {
                die('Could not query:' . mysql_error());
            }
            echo $row['org1'],"<br>";
            echo $row['org2'],"<br>";
            if (! isset($array[$row['org1']])){
                //echo "add<br>";
                $array[$row['org1']] = mysql_result($res,0);
            }
            $q = "select max(output) as max from (select max(greatest(org1_start, org1_end)) as output from ".$session_id."_synteny where org1 like '" . $row['org2'] . "' union select max(greatest(org2_start, org2_end)) as output from ".$session_id."_synteny where org2 like '" . $row['org2'] . "') as t1";
            #echo $q, "<br>";
            $res = mysql_query($q);
            if (!$res) {
                die('Could not query:' . mysql_error());
            }
            if (! isset($array[$row['org2']])){
                //echo "add<br>";
                $array[$row['org2']] = mysql_result($res,0);
            }
        }
    }
    else {
        echo 'Invalid query: ' . mysql_error() . "\n";
        echo 'Whole query: ' . $query;
    }
}
else if ($data == 'order'){
    $query = "select distinct org1 from ".$session_id."_synteny union select distinct org2 from ".$session_id."_synteny ";
    //echo $query,"<br>";
    $result = mysql_query($query);
    $default = array();
    while($row = mysql_fetch_assoc($result)){
        array_push($default, $row['org1']);
    }
    $array = join('__ORDER__', $default);
}
else if ($data == 'sorder'){
    $query = "select distinct org1,org2 from ".$session_id."_synteny union select distinct org1,org2 from ".$session_id."_synteny ";
    //echo $query,"<br>";
    $result = mysql_query($query);
    $default = array();
    $assarr = array();
    while($row = mysql_fetch_assoc($result)){
        if( ! in_array($row['org1'], $default)){
            array_push($default, $row['org1']);
            $assarr[sizeof($assarr)] = array();
        }
        if( ! in_array($row['org2'], $default)){
            array_push($default, $row['org2']);
            $assarr[sizeof($assarr)] = array();
        }
        $len_query = "select sum(org1_end) - sum(org1_start) + sum(org2_end) - sum(org1_start) as sum from ".$session_id."_synteny where (org1 like '".$row['org1']."' and org2 like '".$row['org2']."') OR (org1 like '".$row['org2']."' and org2 like '".$row['org1']."')";
        $q_result = mysql_query($len_query);
        $q_row = mysql_fetch_assoc($q_result);
        #echo $len_query,"<br>";
        #echo $q_row['sum'],"<br>";
        $assarr[array_search($row['org1'], $default)][array_search($row['org2'], $default)] = $q_row['sum'];
        #$assarr[array_search($row['org1'], $default)][array_search($row['org2'], $default)] = 1;
        $assarr[array_search($row['org2'], $default)][array_search($row['org1'], $default)] = $q_row['sum'];
        #$assarr[array_search($row['org2'], $default)][array_search($row['org1'], $default)] = 1;
        #echo array_search($row['org1'], $default) . "][ ". array_search($row['org2'], $default) . '<br>';
        $assarr[array_search($row['org1'], $default)][array_search($row['org1'], $default)] = 0;
        #echo array_search($row['org1'], $default) . "][ ". array_search($row['org1'], $default) . '<br>';
        $assarr[array_search($row['org2'], $default)][array_search($row['org2'], $default)] = 0;
        #echo array_search($row['org2'], $default) . "][ ". array_search($row['org2'], $default) . '<br>';
    }

    $a = FindOrder($assarr);
    $sugg = array();
    //echo sizeof($a),'<br>';
    foreach($a as $b){
        //echo $default[$b],"<br>";
        array_push($sugg, $default[$b]);
    }
    $array = join('__ORDER__', $sugg);
}


function FindOrder($graph){
    $r = array();
    $last = -1;
    while(!isEmpty($graph)){
        $start = leastEdges($graph);
        $path = longestPath($graph, $start, 0);
        $path = completeCycle($graph, $path);
        if($path[0] != $last){
            array_push($r, $path[0]);
        }
        for($x = 1; $x < sizeof($path); $x++){
            array_push($r, $path[$x]);
        }
        $last = $path[sizeof($path)-1];
        $graph = removePath($graph, $path);
    }
    return $r;
}

function longestPath($graph, $cur, $len){
    $path = array();
    array_push($path, $cur);
    $longestSubpath = array();
    for($x = 0; $x < sizeof($graph); $x++){
        if($graph[$cur][$x] != 0){
            $subpath = longestPath(removeVertex($graph, $cur), $x, $len + $graph[$cur][$x]);
            if(sizeof($subpath) > sizeof($longestSubpath)){
                $longestSubpath = $subpath;
            }
        }
    }
    foreach($longestSubpath as $x){
        array_push($path, $x);
    }
    return $path;
}

function completeCycle($graph, $path){
    $graph = removePath($graph, $path);
    $last = $path[sizeof($path)-1];
    for($x = 0; $x < sizeof($graph); $x++){
        if($graph[$last][$x] != 0){
            array_push($path, $x);
            return $path;
        }
    }
    return $path;
}

function removePath($graph, $path){
    for($x = 0; $x < sizeof($path) - 1; $x++){
        $arr = $path[$x]; //***forgot the $ in front of path***
        $b = $path[$x+1]; //***forgot the $ in front of path***
        $graph[$arr][$b] = 0;
        $graph[$b][$arr] = 0;
    }
    return $graph;
}

function removeVertex($graph, $vtx){
    if($vtx < 0 || $vtx >= sizeof($graph)){
        return copy($graph);
    }
    for($x = 0; $x < sizeof($graph); $x++){
        $graph[$x][$vtx] = 0;
        $graph[$vtx][$x] = 0;
    }
    return $graph;
}

function numEdges($vtx){
    $r = 0;
    foreach($vtx as $x){
        if($x != 0){
            $r++;
        }
    }
    return $r;
}

function leastEdges($graph){
    $r = -1;
    $min = 2147483647;
    for($x = 0; $x < sizeof($graph); $x++){
        $e = numEdges($graph[$x]);
        if($e != 0 && $e < $min){
            $r = $x;
            $min = $e;
        }
    }
    return $r;
}

function isEmpty($arr){
    $r = true;
    foreach($arr as $x){
        $r = $r && numEdges($x) == 0;
    }
    return $r;
}

## Return the JSON object
echo json_encode($array);
?>

我创建了一个 docker-compose.yml ,可以通过以下方式运行:

git clone https://github.com/mictadlo/mGSV-docker.git
docker-compose up --build

该服务可以通过localhost访问,PhpMyAdmin可以通过localhost:8183访问

我错过了什么?

提前谢谢

最佳答案

尝试在 Mysql phpmyadmin 中独立运行这两个查询

select distinct org1,org2 from '.304342020180200000016.'_synteny

select distinct org1,org2 from '.304342020180200000016.'_synteny

据我所知,您的查询似乎是正确的,因为联合需要相同的列数和相同的数据类型。

为什么你的联合查询中的表名是相同的。

关于php 联合选择不同的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49603944/

相关文章:

php - 拉脱维亚公民个人代码的正则表达式

查询中的 MySQL 子选择

php - 从一组不同的表创建事件流。

c# - 查询 MySQL 时指定的强制转换无效

apache-kafka - 在 docker 中创建 kafka 主题时出现异常 : partition is not a recognized option,。

docker - 使用 docker-compose 连接到 RabbitMQ 容器

php - '+' 字符串运算符从 C++ 到 PHP

php - 在 Codeigniter 中对 WHERE 子句进行分组

php - Web 服务不适用于 mysql

django - 没有在带有 Docker 的 Django 应用程序上提交工作服