我有这个PHP代码:
$queryGO = "SELECT * from (SELECT g.go as GO, a.gen as Gen, g.descr as Description
FROM geneOntology g, $tabla a where g.go=a.go) resultado
WHERE resultado.go = '$go'";
$result = mysql_query($queryGO, $db);
$items = mysql_affected_rows($db);
$row = mysql_fetch_array($result);
它构造了我这个查询:
SELECT * from ( SELECT g.go as GO, a.gen as Gen, g.descr as Description
FROM geneOntology g, goHuman a where g.go=a.go) resultado
WHERE resultado.go = 'GO:0000012'
在PHP中,它只返回1个项目(和行)但是如果我直接在终端中执行查询,它会抛出15个寄存器:
+------------+--------+----------------------------+
| GO | Gen | Description |
+------------+--------+----------------------------+
| GO:0000012 | APLF | single strand break repair |
| GO:0000012 | APTX | single strand break repair |
| GO:0000012 | E9PIP4 | single strand break repair |
| GO:0000012 | E9PJ82 | single strand break repair |
| GO:0000012 | E9PLZ0 | single strand break repair |
| GO:0000012 | E9PP57 | single strand break repair |
| GO:0000012 | E9PQ18 | single strand break repair |
| GO:0000012 | H0YEW9 | single strand break repair |
| GO:0000012 | LIG4 | single strand break repair |
| GO:0000012 | M0R2N6 | single strand break repair |
| GO:0000012 | Q6ZNB5 | single strand break repair |
| GO:0000012 | SIRT1 | single strand break repair |
| GO:0000012 | TDP1 | single strand break repair |
| GO:0000012 | TNP1 | single strand break repair |
| GO:0000012 | XRCC1 | single strand break repair |
+------------+--------+----------------------------+
15 rows in set (0,04 sec)
我看不出发生了什么。实际上,我在其他php动作中有类似的代码,它执行de query ok ...你能帮帮我吗?
提前致谢!问候。
答案 0 :(得分:3)
使用while循环遍历返回,只返回一行:
while($row = mysql_fetch_array($result)){
print_r($row);
}
请停止使用mysql_ *函数。这些扩展已在PHP 7中删除。了解PDO和MySQLi的预处理语句并考虑使用PDO,这非常简单。