I attempted to adapt Weedpacket's code in the frequently asked questions, and it's getting closer - but I'm only displaying the 1st result in each cell. How can I get all results that I know exist (in this case, 3 results) so that picture 1 and 2 would appear in the top 2 cells, and picture 3 appears in the bottom left cell?
$query_images = "select id, name, path, type, size
FROM images
WHERE name LIKE '508429%'";
$result_images = mysql_query($query_images);
$row_images = mysql_fetch_array($result_images);
<table width="300" cellspacing="1" cellpadding="2" border="2">
<tr>
<?php
//number of columns we want:
$display_columns = 2;
// We do the query, and find out how many items we'll need to list.
$count = mysql_num_rows($result_images);
// We have enough to figure out how many empty spaces there'll be left at
// the bottom of the table.
$padding = ($display_columns-1)-(($count-1)%$display_columns);
//
// We also know enough to know how many rows there'll be, but I for one
// don't really care about that right now.
//echo '<table border="1">';
// Let's begin our loop.
for($i=0; $i<$count; $i++)
{ // Whenever $i is a multiple of $display_columns (including 0),
// it's a sign that we're hitting the start of a new row.
if($i%$display_columns == 0)
echo '<tr>';
//Now for an item.
echo '<td>';
echo '<img src="'.$row_images['path'].'">';
echo '</td>';
//Whenever $i is one less than a multiple of $display_columns,
// it's a sign that we're hitting the end of the current row.
if($i%$display_columns == $display_columns-1)
echo '</tr>';
}
// That's all the items done; now we just need to pad the table out and
// wrap up. We don't need to pad at all if $padding is zero.
if($padding!=0)
{ for($i=0;$i<$padding;$i++)
echo '<td></td>';
echo '</tr>';
}
?>
</tr>
</table>