我在我的表中进行了标准化:
从 :tb_1
===================================
| id | doc_name | title | author |
===================================
| 1 | doc1 | title1 | author1|
| | | | author2|
| 2 | doc2 | title2 | author3|
| | | | author4|
===================================
变得 :
tb_a tb_b
======================= =========================
|id_a|doc_name| title | |id_b| doc_name| author |
======================= =========================
| 1 | doc1 | title1| | 1 | title1 |author1 |
| 2 | doc2 | title2| | 2 | title1 |author2 |
======================= | 3 | title2 |author3 |
| 4 | title2 |author2 |
=========================
我想显示如下结果:
doc1 title1 author1 author2
doc2 title2 author3 author4
这是代码:
$query = mysql_query(" SELECT tb_a.doc_name, tb_a.title,
tb_b.doc_name, tb_b.author
FROM tb_a
JOIN tb_b ON tb_a.doc_name = tb_b.doc_name ");
while ($row = mysql_fetch_array($query)) {
$doc = $row['doc_name'];
$title = $row['title'];
$author = $row['author'];
echo $doc; echo $title ; echo $author;
}
但结果是:
doc1 title1 author1
doc1 title1 author2
doc2 title2 author3
doc2 title2 author4
请帮助我,非常感谢你:)