Problems outputting to a 3 column table in order to crate an image gallery

Hi there,

I’m trying to query a MySQL database (containing image data) and to output
the results in a HTML table of 3 columns wide (and however many rows it
takes) in order to create a basic thumbnail gallery.

I can query and output the data as a single column table, but I’m having
problems filling up a 3 column table (with different images, looping
continuously until the end).

I would appreciate it if someone could take a look at the code below and
point me in the right direction or suggest any extra lines of code which
would finish the job?

The code below puts an image on each row, instead of filling up 3 columns on
each row with a different image.

I open this gallery by going to (i.e. to access the landscape

Thank you for any help,



$connection = mysql_connect($host,$user,$password) or die (“couldn’t connect
to server”);
$db = mysql_select_db($database,$connection) or die (“Couldn’t select

$title = “Gallery”;
$query = “SELECT * FROM mydatabase WHERE imagetype =
$result = mysql_query($query) or die (“Couldn’t execute query.”);

echo “<h2 >$title</h2>”;
echo “<table >”;
echo “<tbody >”;

while ($row = mysql_fetch_array($result))

echo “<tr >”;
echo “<td ><img src=\”$imagelocation\” />\n
</td >\n”;

echo “</tr >”;
echo “</table >\n”;
? >

Leave a Reply

Your email address will not be published. Required fields are marked *