使用 php,我试图链接由相同值连接的 3 个表的结果。然后,我希望每个动态的相关结果集在页面上作为 while 循环重复。这是我想要的结果:
艺术家->
series1->piece1,piece2
series2->piece3,piece4
艺术家和系列表共享一个名为“艺术家”的匹配列。系列和片断表具有匹配的列名“系列”。我知道这些表是通过数据库中的相同匹配值链接的,因为在另一个页面上级联删除正在工作。
目前,它仅将系列显示为回声重复循环,但两边都没有艺术家或作品相关。像这样:http ://www.exhibitjewellery.com/artistindex.php
mysql_fetch_assoc 是否正确,我不确定。我对表格是否正确链接或者问题是否在于我如何划分正文部分进行格式化感到困惑。我有一种感觉,多维数组可能会帮助甚至嵌套表格,但我还没有完全掌握所有细节如何在代码的每个部分中组合在一起。请帮忙!
头顶上的PHP:
<?php
mysql_select_db($database_connectmysql, $connectmysql);
$query_artistrecordset = "SELECT * FROM artists ORDER BY artist ASC";
$artistrecordset = mysql_query($query_artistrecordset, $connectmysql) or die(mysql_error());
$row_artistrecordset = mysql_fetch_assoc($artistrecordset);
$totalRows_artistrecordset = mysql_num_rows($artistrecordset);
mysql_select_db($database_connectmysql, $connectmysql);
$query_seriesrecordset = "SELECT * FROM series, artists WHERE series.artist=artists.artist ORDER BY exhibition ASC";
$seriesrecordset = mysql_query($query_seriesrecordset, $connectmysql) or die(mysql_error());
$resultseries = mysql_query($query_seriesrecordset);
$row_seriesrecordset = mysql_fetch_assoc($resultseries);
$totalRows_seriesrecordset = mysql_num_rows($seriesrecordset);
mysql_select_db($database_connectmysql, $connectmysql);
$query_piecerecordset = "SELECT * FROM pieces,series WHERE pieces.piece=series.series ORDER BY piece ASC";
$piecerecordset = mysql_query($query_piecerecordset, $connectmysql) or die(mysql_error());
$resultpiece = mysql_query($query_piecerecordset);
$row_piecerecordset = mysql_fetch_assoc($resultpiece);
$totalRows_piecerecordset = mysql_num_rows($piecerecordset);
?>
这就是我试图在体内呼应它的方式:
<div id="serieslist" align="right">
<?php echo $row_artistrecordset['artist']; ?><br />
<?php echo $row_artistrecordset['website']; ?><br />
<?php echo $row_artistrecordset['artist_statement']; ?><br />
<?php do { ?>
<?php echo $row_seriesrecordset['series']; ?><br />
<?php echo $row_seriesrecordset['exhibition']; ?><br />
<?php echo $row_seriesrecordset['series_statement']; ?><br />
<?php do { ?>
<?php echo $row_piecerecordset['piece']; ?><br />
<?php echo $row_piecerecordset['description']; ?><br />
<?php echo $row_piecerecordset['category']; ?><br />
<?php echo $row_piecerecordset['dimensions']; ?><br />
<?php echo $row_piecerecordset['price']; ?><br />
add to collection button<br />
<?php } while ($row_piecerecordset = mysql_fetch_assoc($resultpiece)); ?>
<?php } while ($row_seriesrecordset = mysql_fetch_assoc($resultseries)); ?>
</div>
</body>
</html>
<?php
mysql_free_result($artistrecordset);
mysql_free_result($seriesrecordset);
mysql_free_result($piecerecordset);
?>
任何帮助将不胜感激,因为我已经为此工作了几天!