So my problem is i am exporting images from a table called “BikeImages” within this table theres images that our under the same foreign Key BikeCode. How do i make sure the images are added together instead of seperately.
For Example
BikeCode: 123
BikeImages: IMAGE1, IMAGE2
BikeCode: 14
BikeImages 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>";
}
?>
Thank you in advance for your help.
EDIT: I have to combine this code with the above code:
<?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";
?>
Don’t put the table tag in the loop, but outside
With the two selects, you have an outer loop going through bikes and an inner loop iterating over the images. An “easy” but expensive solution, could be