所以我的问题是我正在从这个表中的一个名为“BikeImages”的表中导出图像,我们在同一个外键 BikeCode 下的图像。我如何确保图像被添加在一起而不是单独添加。
例如
自行车代码:123
自行车图像:IMAGE1、IMAGE2
自行车代码:14
自行车图像 IMAGE1
<?php
$sql1 = "SELECT BikeCode, Manufacturer, Model, SubType, Year, FrameMaterial, Description, Gender, Type, Price, Stock FROM Bike WHERE Stock > 0";
$result1 = mysqli_query($con, $sql1);
while(list($bikecode, $manufacturer, $model, $subtype, $year, $fmaterial, $desc, $gender, $type, $price, $stock) = mysqli_fetch_row($result1)) {
echo "
<table>
<tr><th>BikeCode:</th>
<th>Manufacturer:</th>
<th>Model:</th>
<th>Subtype:</th>
<th>Year:</th>
</tr>
<tr>
<td>$bikecode</td>
<td>$manufacturer</td>
<td>$model</td>
<td>$subtype</td>
<td>$year</td>
</tr>
<tr>
<th>FrameMaterial:</th>
<th>Gender:</th>
<th>Type:</th>
<th>Price:</th>
<th>Stock:</th>
</tr>
<tr>
<td>$fmaterial</td>
<td>$gender</td>
<td>$type</td>
<td>£$price</td>
<td>$stock</td>
</tr>
<tr><th>Description:</th><td colspan=\"4\">$desc</td></tr>
<tr><th>Bike Images:</th><td colspan=\"4\"><a href=\"$sourcepath\" title=\"$description\"><img src=\"$sourcepath\" width=\"72\" height=\"72\" /></a></td></tr>
<tr><th>Order Now:</th><td colspan=\"4\"><a href=\"basket.php?action=add&id=$bikecode\">Add To Cart</a></td></tr>
</table>";
}
?>
预先感谢您的帮助。
编辑:我必须将此代码与上面的代码结合起来:
<?php
$sql = "SELECT SourcePath, Description, BikeCode FROM BikeImages order by bikecode";
$result = mysqli_query($con, $sql);
$previous = -1;
echo "<table>";
while(list($sourcepath, $description, $bcode) = mysqli_fetch_row($result)) {
// if bikecode changed, append "Order now"
if ($previous != -1 && $previous != $bcode) {
echo "<tr><th>Order Now:</th><td colspan=\"4\"><a href=\"basket.php?action=add&id=$previous\">Add To Cart</a></td></tr>";
}
echo "<tr><th>Bike Images:</th><td colspan=\"4\">";
echo "<a href=\"$sourcepath\" title=\"$description\"><img src=\"$sourcepath\" width=\"72\" height=\"72\" /></a>";
echo "</td></tr>";
$previous = $bcode;
}
echo "</table>\n";
?>