好,最简单的事情是为你重复代码块3倍。每一次,与传递给查询不同的艺术家ID:
<?php
include "Connection.php";
$sql = "SELECT artist.artistName, artistcd.artistID, artistcd.cdID, artistcd.cdTitle, artistcd.cdGenre, artistcd.cdPrice
FROM artist, artistcd
WHERE artist.artistID = "$ArtistID1";
$query = mysqli_query($connect, $sql) or die("Error: ".mysqli_error($connect));;
$name = mysqli_fetch_assoc($query);
echo "<p>" . $name["artistID"] . $name["artistName"] . "</p>";
?>
<table width="70%" cellpadding="5" cellspace="5">
<tr>
<th>Genre</th>
<th>CD Identification</th>
<th>Title</th>
<th>Price</th>
</tr>
<?php
while ($row = mysqli_fetch_assoc($query)) {
echo "<tr>";
echo "<td>" . $row['cdGenre']. "</td>";
echo "<td>" . $row['cdID']. "</td>";
echo "<td>" . $row['cdTitle']. "</td>";
echo "<td>" . $row['cdPrice']. "</td>";
echo "</tr>";
}
?>
<table width="70%" cellpadding="5" cellspace="5">
</table>
<?php
$sql = "SELECT artist.artistName, artistcd.artistID, artistcd.cdID, artistcd.cdTitle, artistcd.cdGenre, artistcd.cdPrice
FROM artist, artistcd
WHERE artist.artistID = "$ArtistID2";
$query = mysqli_query($connect, $sql) or die("Error: ".mysqli_error($connect));;
$name = mysqli_fetch_assoc($query);
echo "<p>" . $name["artistID"] . $name["artistName"] . "</p>";
?>
<table width="70%" cellpadding="5" cellspace="5">
<tr>
<th>Genre</th>
<th>CD Identification</th>
<th>Title</th>
<th>Price</th>
</tr>
<?php
while ($row = mysqli_fetch_assoc($query)) {
echo "<tr>";
echo "<td>" . $row['cdGenre']. "</td>";
echo "<td>" . $row['cdID']. "</td>";
echo "<td>" . $row['cdTitle']. "</td>";
echo "<td>" . $row['cdPrice']. "</td>";
echo "</tr>";
}
?>
<table width="70%" cellpadding="5" cellspace="5">
</table>
<?php
$sql = "SELECT artist.artistName, artistcd.artistID, artistcd.cdID, artistcd.cdTitle, artistcd.cdGenre, artistcd.cdPrice
FROM artist, artistcd
WHERE artist.artistID = "$ArtistID3";
$query = mysqli_query($connect, $sql) or die("Error: ".mysqli_error($connect));;
$name = mysqli_fetch_assoc($query);
echo "<p>" . $name["artistID"] . $name["artistName"] . "</p>";
?>
<table width="70%" cellpadding="5" cellspace="5">
<tr>
<th>Genre</th>
<th>CD Identification</th>
<th>Title</th>
<th>Price</th>
</tr>
<?php
while ($row = mysqli_fetch_assoc($query)) {
echo "<tr>";
echo "<td>" . $row['cdGenre']. "</td>";
echo "<td>" . $row['cdID']. "</td>";
echo "<td>" . $row['cdTitle']. "</td>";
echo "<td>" . $row['cdPrice']. "</td>";
echo "</tr>";
}
?>
<table width="70%" cellpadding="5" cellspace="5">
</table>
另一种方法是为所有的艺术家查询一次,并通过直接从关联数组过滤艺术家打造的3个表。但正如你所说,你刚刚开始,我认为这个解决方案会做到这一点。
花空数组,然后同时申请一次,并指定所有的值该数组,然后使用该数组变量分为三个不同的表 –
有什么区别3桌之间?有没有需要做的分组?您可能需要进行3个独立的查询。或者在for循环中定义一个用于在3分割结果的逻辑。 –
@LeonelAtencio是的3个表显示3个不同的艺术家的名字,并有3个不同的歌曲 –