我是php的新手....对于下面提到的条件的plzz帮助。 我有桌子。
表1 - 文献
Org_id | literature_id| name | type
-------------------------------------------------
---------------------------------------------
1 | 1 | xxxx | yyyyy
-------------------------------------------------
---------------------------------------------
2 | 2 |xxxx |Yyyyy
-------------------------------------------------
---------------------------------------------
表2 - 生物
Bio_id |literature_id| title1 | title2 | Org_id
------------------------------------------------------------------
------------------------------------------------------------------
1 | 1 | xxxxxx | Marian species | 1
------------------------------------------------------------------
------------------------------------------------------------------
2 | 1 | xxxx | Yyyyy | 2
------------------------------------------------------------------
------------------------------------------------------------------
表3-生物地理学
Com_id |literature_id| title1 |title2 |Org_id
------------------------------------------------------------------
------------------------------------------------------------------
1 | 2 | xxx |yyyy |1
------------------------------------------------------------------
------------------------------------------------------------------
2 | 2 | xxxx |Yyyyy |2
------------------------------------------------------------------
------------------------------------------------------------------
表4- common_name
$result1 = mysql_query("SELECT lit.literature_id, lit.title1, lit.title2
FROM lit
INNER JOIN Organism on lit.literature_id = Organism.literature_id
WHERE organism_id='$org1'
UNION ALL
SELECT lit.literature_id, lit.title1, lit.title2
FROM lit
INNER JOIN biogeography on lit.literature_id = biogeography.literature_id
WHERE organism_id='$org1'
UNION ALL
SELECT lit.literature_id, lit.title1, lit.title2
FROM lit
INNER JOIN ecology on lit.literature_id = ecology.literature_id
WHERE organism_id='$org1'
");
while($row = mysql_fetch_row($result1)) {
echo "
<td>$row[0]</td>
<td><i><b>'$row[1]',
'$row[2]'</i></b><br>
</td>
<td>$row[8]</td>
</tr>";
如上表所示,表中有文献和组织表的详细信息,bio,com表以文献_id的形式参考文献。现在我想从所有表中取出那些literature_id到文献表中获取文献和显示的详细信息。
实施例: - 有机体id'1'有来自表Organism,Biogeography,common_name的参考文献_id 1,1,2。 现在我想显示org_id'1'($ org1)的所有参考文献及其文献详情。
怎么做?以及如何删除重复出现的文献_id ??因为它只会在显示记录时重复。(详情将与literature_id的文献相同)。
我使用下面的代码执行相同的操作,但我的输出可以在结果图像中看到。这是错误的,因为记录正在重复;当我显示记录时,我不想重复。请帮帮我....
代码是:
{{1}}
答案 0 :(得分:0)
试试这个:
$result1 = mysql_query("SELECT lit.literature_id, lit.title1, lit.title2
FROM lit
INNER JOIN Organism on lit.literature_id = Organism.literature_id
WHERE organism_id='$org1'
UNION ALL
SELECT lit.literature_id, lit.title1, lit.title2
FROM lit
INNER JOIN biogeography on lit.literature_id = biogeography.literature_id
WHERE organism_id='$org1'
UNION ALL
SELECT lit.literature_id, lit.title1, lit.title2
FROM lit
INNER JOIN ecology on lit.literature_id = ecology.literature_id
WHERE organism_id='$org1' group by lit.literature_id
");
while($row = mysql_fetch_row($result1)) {
echo "
<td>$row[0]</td>
<td><i><b>'$row[1]',
'$row[2]'</i></b><br>
</td>
<td>$row[8]</td>
</tr>";