This will display your images in a table of 4 columns wide by however many rows needed. If the number of images is not divisible by 4 it will print an empty cell instead.
Line breaks are added to make the generated html source code pretty
echo "<table><tr>\n";
$columns = 4;
$no_of_images = count($images); //image filenames are in array $images
$count = 0;
for ($i = 0; $i <= $no_of_images; $i++)
{
if ($images[$p] != "") //checks to see if there is image information
{
echo "<td><img src=\"".$images[$i]."\"></td>\n";
$count++;
if ($count%$columns == "0")
{
echo "</tr><tr>\n";
}
}
else
{
echo "<td></td>\n"; //prints empty cell if there is no image information
}
}
echo "</tr></table>\n";