Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在mysql+php查询中查询两个表以获得结果_Php_Mysql - Fatal编程技术网

在mysql+php查询中查询两个表以获得结果

在mysql+php查询中查询两个表以获得结果,php,mysql,Php,Mysql,我有两张桌子 表1包含以下字段: | Ensemble_ID | varchar(50) | NO | PRI | | | | Target | text | YES | | NULL | | | Gene_Length | int(5) | YES | | NULL | | | miRNA | varchar(50) | NO | PRI |

我有两张桌子

表1包含以下字段:

| Ensemble_ID | varchar(50) | NO   | PRI |         |       |
| Target      | text        | YES  |     | NULL    |       |
| Gene_Length | int(5)      | YES  |     | NULL    |       |
| miRNA       | varchar(50) | NO   | PRI |         |       |
| position    | int(4)      | YES  |     | NULL    |       |
| Prediction  | text        | YES  |     | NULL    |       |
我的表2包含以下字段:

|Ensemble_ID   | varchar(50)  | NO   | PRI |         |       |
| miRNA        | varchar(50)  | NO   | PRI |         |       |
| miRNA_Length | int(2)       | YES  |     | NULL    |       |
| mfe          | decimal(2,0) | YES  |     | NULL    |       |
| pvalue       | decimal(4,0) | YES  |     | NULL    |       |
| no_of_seeds  | int(1)       | YES  |     | NULL    |       |
我需要这样的结果

|Ensemble_ID    |Gene Length|miRNA|miRNA Length|mfe|P-value|Position|Prediction|No of Seeds|
我是mysql的新手。有人能帮我写一个问题吗

谢谢你的帮助

这是我的php附件。。我无法获得结果,因为它显示查询错误

<?php
$a = $_REQUEST["miRNA"];
$b = $_REQUEST["target"];
// $result = db::table("`table`") -> pluck("*") -> where("miRNA",$a) -> select() -> get();
$mysqli = new mysqli("localhost", "root", "password", "mysql");
$a = $mysqli -> escape_string($a);
$b = $mysqli -> escape_string($b);
$a = $mysqli->query("SELECT * FROM bio3 WHERE miRNA = '$a' AND Target LIKE '%$b' INNER JOIN bio4 on bio3.ensemble_id = bio4.ensemble_id  ORDER BY bio4.pvalue ASC;");


// $result = $a -> fetch_assoc();
$i = 0;
while ($row = $a -> fetch_assoc()) {
$result[$i] = $row;
$i++;

}
$mysqli->close();
for($a=0;$a<sizeof($result);$a++){
print '<tr>
<td>'.htmlentities($result[$a]["Target"]).'</td>
<td>'.htmlentities($result[$a]["Gene Length"]).'</td>
<td>'.htmlentities($result[$a]["miRNA"]).'</td>
<td>'.htmlentities($result[$a]["miRNA Length"]).'</td>
<td>'.htmlentities($result[$a]["mfe"]).'</td>
<td>'.htmlentities($result[$a]["pvalue"]).'</td>
<td>'.htmlentities($result[$a]["position"]).'</td>
<td>'.htmlentities($result[$a]["Prediction"]).'</td>
<td>'.htmlentities($result[$a]["No of Seeds"]).'</td>
</tr>';
}
?>
连接两个表,如:

SELECT t1.Ensemble_ID, t1.Gene_Length, t1.miRNA, t2.miRNA_Length, t2.mfe, t2.pvalue, t1.position, t1.Prediction, t2.no_of_seeds
FROM table1 t1 INNER JOIN table2 t2
ON t1.Ensemble_ID = t2.Ensemble_ID
WHERE t1.miRNA = 'abc' 
AND t1.target LIKE '%xyz' 
ORDER BY t2.pvalue ASC;

使用Join可获得所需的结果。见下文:

SELECT 
      A.Ensemble_ID,
      Gene_Length,
      A.miRNA,
      miRNA_Length,
      mfe,
      Pvalue,
      Position,
      Prediction,
      No_of_Seeds,
FROM Table1 A
JOIN
Table2 A ON A.Ensemble_ID=B.Ensemble_ID

您可以像这样进行查询

SELECT 
  A.Ensemble_ID,
  Gene_Length,
  A.miRNA,
  B.miRNA_Length,
  B.mfe,
  B.Pvalue,
  Position,
  Prediction,
  No_of_Seeds,
FROM Table1 A
JOIN
Table2 B ON A.miRNA=B.miRNA

这是我写的查询,但我知道必须添加一些连接$a=$mysqli->querySELECT*来自bio3,bio4,其中miRNA='$a'和目标类似于“%$b”,按bio3排序。'pvalue ASC@ramko如果你觉得上面有帮助,那么你应该接受它,这样其他人可以从中受益。